GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   any C# programmers on here? (https://gfy.com/showthread.php?t=1036596)

acctman 09-02-2011 04:03 PM

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 09-02-2011 05:06 PM

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

nikki99 09-02-2011 05:07 PM

I failed at c++ at university :(

WarChild 09-02-2011 05:09 PM

Tical beat me to it.

acctman 09-02-2011 05:15 PM

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.

tical 09-02-2011 05:51 PM

Quote:

Originally Posted by acctman (Post 18400398)
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.

WarChild 09-02-2011 06:05 PM

Quote:

Originally Posted by tical (Post 18400449)
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. :2 cents:

acctman 09-02-2011 08:29 PM

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;
                }
            }


tical 09-02-2011 09:30 PM

Quote:

Originally Posted by acctman (Post 18400610)
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;
                }
            }


Mr Pheer 09-02-2011 10:13 PM

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?

Chosen 09-03-2011 06:20 AM

Asm programmer for Z80 processors here :pimp

acctman 09-03-2011 07:44 AM

Quote:

Originally Posted by Mr Pheer (Post 18400711)
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.


All times are GMT -7. The time now is 03:15 PM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123