any C# programmers on here?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • acctman
    Confirmed User
    • Oct 2003
    • 2840

    #1

    any C# programmers on here?

    Please disregard the two For Statement they're wrong and outputting multiple ListID entries of the same thing. That's the problem and I need help fixing it. The MakeReq function has nothing to do with my problem its just holding values like an array does.

    Code:
    if (listId.Items.Count != 0 && listCell.Items.Count != 0)
            {
                for (int a = 0; a < listId.Items.Count; a++)
                {
                    for (int b = 0; b < listCell.Items.Count; b++)
                    {
                        lblID.Text = listId.Items[a].ToString();
                        MakeReq(txtWebUpdate.Text + listId.Items[a].ToString() + 
                            "&ire=1", listCell.Items[b].ToString());
                        //System.Threading.Thread.Sleep(5);
                    }
                }
            }
    this is the output i'm trying to accomplish (domain, listID, presetString, listCell)

    store.domain.com 101 &ire=1 sec01
    store.domain.com 102 &ire=1 sec02
    store.domain.com 103 &ire=1 sec03
    store.domain.com 104 &ire=1 sec04
    store.domain.com 105 &ire=1 sec01
    store.domain.com 106 &ire=1 sec02 <- ^ notice how listCell started over for the last two entries. that's because listCell only has 4 entry so it continuously loops applying secIDs until all ListIDs have been processed. So there maybe 500 ListID and only 20 listCell secIDs, which means listCell will just loop within itself applying the same secIDs from the top of its list down, again and again.

    it's a simple concept, but you won't believe how many C# programmers are clueless as to what i'm trying to accomplish.
  • tical
    Confirmed User
    • Feb 2002
    • 6504

    #2
    here you go, just remove/replace the temporary stuff w/ your stuff

    Code:
                List<string> listId = new List<string>();
                List<string> listCell = new List<string>();
                listId.Add("id1");
                listId.Add("id2");
                listId.Add("id3");
                listId.Add("id4");
                listId.Add("id5");
                listId.Add("id6");
                listCell.Add("cell1");
                listCell.Add("cell2");
                listCell.Add("cell3");
                listCell.Add("cell4");
    
                int listCellCounter = 0;
                for (int x = 0; x < listId.Count; x++)
                {
                    Debug.WriteLine("something " + listId[x] + " " + listCell[listCellCounter]);
                    if (listCellCounter == listCell.Count() -1)
                    {
                        listCellCounter = 0;
                    }
                    else
                    {
                        listCellCounter += 1;
                    }
                }
    output looks like this:

    something id1 cell1
    something id2 cell2
    something id3 cell3
    something id4 cell4
    something id5 cell1
    something id6 cell2
    112.020.756

    Comment

    • nikki99
      Supermodel
      • Nov 2004
      • 23087

      #3
      I failed at c++ at university
      SMC Revenue - Best Tgirl websites of the world now VR
      Non exclusive BIG Tranny/shemale Package for sale, full 2257 - hit me up skype: nikkimontero

      Comment

      • WarChild
        Let slip the dogs of war.
        • Jan 2003
        • 17263

        #4
        Tical beat me to it.
        .

        Comment

        • acctman
          Confirmed User
          • Oct 2003
          • 2840

          #5
          tical THANK YOU! ... been at this for over a week.

          another question is System.Threading.Thread.Sleep() the best method for pausing/sleeping? I used it earlier where trying to debug and it felt like it was hang the app.
          Last edited by acctman; 09-02-2011, 04:19 PM.

          Comment

          • tical
            Confirmed User
            • Feb 2002
            • 6504

            #6
            Originally posted by acctman
            tical THANK YOU! ... been at this for over a week.

            another question is System.Threading.Thread.Sleep() the best method for pausing/sleeping? I used it earlier where trying to debug and it felt like it was hang the app.
            If you've got the Thread.Sleep() in a Form it will hang your app. I use it to pause / slow down threads all of the time. You just have to use it the right way to avoid making it seem like it's hanging your app.

            If you're calling something like:

            void dowork
            {
            // some code
            // loop w/ sleep
            // other code
            }

            Then "other code" won't execute until the loop w/ sleep is done, so if there are a ton of listids then it might seem like it's lagging. Plus your form is going to get "stuck" during each sleep iteration.

            If you want to have it run in the background without having that error. Then do something like this:

            void listidloop
            {
            // your loop code w/ thread.sleep, etc.
            }

            and in the function you're calling it from (form or other class):

            Thread t = new Thread(listidloop);
            t.Start();

            That way it operates in a separate thread and doesn't lock up your form. The problem here is if the listidloop function is trying to update the form form (ie, textbox1.text = "", etc) then you're going to get a cross thread error and will need to use delegates/invoking for this.
            112.020.756

            Comment

            • WarChild
              Let slip the dogs of war.
              • Jan 2003
              • 17263

              #7
              Originally posted by tical
              If you've got the Thread.Sleep() in a Form it will hang your app. I use it to pause / slow down threads all of the time. You just have to use it the right way to avoid making it seem like it's hanging your app.

              If you're calling something like:

              void dowork
              {
              // some code
              // loop w/ sleep
              // other code
              }

              Then "other code" won't execute until the loop w/ sleep is done, so if there are a ton of listids then it might seem like it's lagging. Plus your form is going to get "stuck" during each sleep iteration.

              If you want to have it run in the background without having that error. Then do something like this:

              void listidloop
              {
              // your loop code w/ thread.sleep, etc.
              }

              and in the function you're calling it from (form or other class):

              Thread t = new Thread(listidloop);
              t.Start();

              That way it operates in a separate thread and doesn't lock up your form. The problem here is if the listidloop function is trying to update the form form (ie, textbox1.text = "", etc) then you're going to get a cross thread error and will need to use delegates/invoking for this.
              If you're going to do it in a sepeare thread, it might be worth throwing in an application.processmessages too.
              .

              Comment

              • acctman
                Confirmed User
                • Oct 2003
                • 2840

                #8
                am i doing this correctly, trying replace the pre-loaded entries from your example with my actual listboxs for loading/processing

                Code:
                List<string> listId = new List<string>();
                foreach(var item in this.listId.Items)
                {
                    listId.Add(item.ToString());
                }
                List<string> listCell = new List<string>();
                foreach(var item in this.listCell.Items)
                {
                    listCell.Add(item.ToString());
                }
                
                
                int listCellCounter = 0;
                            for (int x = 0; x < listId.Count; x++)
                            {
                                Debug.WriteLine("something " + listId[x] + " " + listCell[listCellCounter]);
                                if (listCellCounter == listCell.Count() -1)
                                {
                                    listCellCounter = 0;
                                }
                                else
                                {
                                    listCellCounter += 1;
                                }
                            }

                Comment

                • tical
                  Confirmed User
                  • Feb 2002
                  • 6504

                  #9
                  Originally posted by acctman
                  am i doing this correctly, trying replace the pre-loaded entries from your example with my actual listboxs for loading/processing

                  Code:
                  List<string> listId = new List<string>();
                  foreach(var item in this.listId.Items)
                  {
                      listId.Add(item.ToString());
                  }
                  List<string> listCell = new List<string>();
                  foreach(var item in this.listCell.Items)
                  {
                      listCell.Add(item.ToString());
                  }
                  
                  
                  int listCellCounter = 0;
                              for (int x = 0; x < listId.Count; x++)
                              {
                                  Debug.WriteLine("something " + listId[x] + " " + listCell[listCellCounter]);
                                  if (listCellCounter == listCell.Count() -1)
                                  {
                                      listCellCounter = 0;
                                  }
                                  else
                                  {
                                      listCellCounter += 1;
                                  }
                              }
                  Actually you don't need to pre-populate a list. You should be able to use your existing collections:

                  Something like this, my sytax may be off a bit... but it should be clear! Hope that helps

                  Code:
                              int listCellCounter = 0;
                              for (int x = 0; x < listId.Items.Count; x++)
                              {
                                  Debug.WriteLine("something " + listId.Item[x] + " " + listCell.Item[listCellCounter]);
                                  if (listCellCounter == listCell.Items.Count() -1)
                                  {
                                      listCellCounter = 0;
                                  }
                                  else
                                  {
                                      listCellCounter += 1;
                                  }
                              }
                  112.020.756

                  Comment

                  • Mr Pheer
                    So Fucking Banned
                    • Dec 2002
                    • 22083

                    #10
                    Remember when you copied my webcam page and left my counter code on it? That was some funny shit.

                    Still got that BMW you did all the custom work to?

                    Comment

                    • Chosen
                      • Aug 2001
                      • 63151

                      #11
                      Asm programmer for Z80 processors here

                      Comment

                      • acctman
                        Confirmed User
                        • Oct 2003
                        • 2840

                        #12
                        Originally posted by Mr Pheer
                        Remember when you copied my webcam page and left my counter code on it? That was some funny shit.

                        Still got that BMW you did all the custom work to?
                        Spunky! LOL that was back during the ynot irc chat. hey man what's up, how have you been? Still got the BMW, just hit 66k miles on it. I stopped customizing it after I won first place at NOPI Nationals, that's all I wanted.
                        Last edited by acctman; 09-03-2011, 06:45 AM.

                        Comment

                        Working...