Results 1 to 5 of 5

Thread: Do I need Control.Invoke()?

  1. #1

    Thread Starter
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690

    Do I need Control.Invoke()?

    I'm wondering if this code is ok or if maybe I should be doing Control.Invoke(). Not that I know how to do .Invoke. The code seems to run just fine.

    Code:
    private void btnLogon_Click(object sender, System.EventArgs e)
    {
    	Thread t = new Thread(new ThreadStart(IncrementProgressBar));
    	t.Start();
    .
    .
    .
    
    private void IncrementProgressBar()
    {
    	do
    	{
    		if (progressBar1.Value >= 95)
    		{
    		        progressBar1.Value = 0;
    		}
    		progressBar1.Value += 5;
    		Thread.Sleep(250);
    	}
    	while (true);
    }
    I thought there was a trick with modifying a control from a different thread, but not sure if you only need to do that with a method and not a property.

    Thanks,
    Mike

  2. #2
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    You should be using invoke if you are talking accross threads. This is a weird one cause it is miss-leading. Windows XP has a "feature" that allows this to work, yet, from everywhere I have heard this, the other OS's don't allow you to do it. So if your code was running on a different OS, you might have some problems. You might want to do some good testing.

  3. #3

    Thread Starter
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    ok. Any idea how one would write that code using .Invoke? I've searched and read, but don't quite get it.

    Mike

  4. #4

  5. #5

    Thread Starter
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    Thanks for the links. Need to get my head around all the delegate stuff. Thanks.

    Mike

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width