View Single Post
Old 09-02-2011, 05:51 PM  
tical
Confirmed User
 
Join Date: Feb 2002
Location: Las Vegas
Posts: 6,504
Quote:
Originally Posted by acctman View Post
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
tical is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote