Solved

BeginInvoke - name the thread

Posted on 2004-04-23
8
759 Views
Last Modified: 2012-05-04
Would someone show me how to name the thread launched by a BeginInvoke call?

Thanks,

MT
0
Comment
Question by:supertedusa
  • 4
  • 2
  • 2
8 Comments
 
LVL 10

Expert Comment

by:eternal_21
ID: 10901553
I don't think there is any way for you to control this.  There is no rule that says a "BeginInvoke" method even has to create a new thread, or that it doesn't create more than one.
0
 

Author Comment

by:supertedusa
ID: 10901611
I built part of my app from this starting point:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnforms/html/winforms06112002.asp

delegate void ShowProgressDelegate(string pi, int totalDigits, int digitsSoFar);

void CalcPi(int digits) {
  StringBuilder pi = new StringBuilder("3", digits + 2);

  // Get ready to show progress asynchronously
  ShowProgressDelegate showProgress =
    new ShowProgressDelegate(ShowProgress);

  // Show progress
  this.Invoke(showProgress, new object[] { pi.ToString(), digits, 0});

  if( digits > 0 ) {
    pi.Append(".");

    for( int i = 0; i < digits; i += 9 ) {
      ...
      // Show progress
      this.Invoke(showProgress,
        new object[] { pi.ToString(), digits, i + digitCount});
    }
  }
}


It was my understanding that using delegates/BeginInvoke forced the method to be run on a new thread?  The UI is certainly respsonsive during the operations.  Am I off base on this?
0
 
LVL 23

Expert Comment

by:rama_krishna580
ID: 10901727
look at here..u got u r answer...

http://www.dotnet247.com/247reference/msgs/11/55668.aspx

best of luck..

R.K.
0
 

Author Comment

by:supertedusa
ID: 10901940
Thanks for the reference, but it looks like it's just another way of threading, I think?

So if I'm using:

del = new DelegateMy(m_Del.SomeMethod);
BeginInvoke(del, new object[]{parm1, parm2, parm3, [,etc...]});

from my main form, am I spawning a new thread this way?  The UI does not lock up on me and I'm able to make several calls to methods on the main form from the delegate method that update the main UI.

Just trying to get some clarity on the concepts and name the threads, if possible.

Thanks,

MT
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 10

Expert Comment

by:eternal_21
ID: 10902065
If you followed the MSDN example, you should have the following code:

  Thread piThread = new Thread(new ThreadStart(CalcPiThreadStart));
  piThread.Start();

You can name your thread at this point:

  Thread piThread = new Thread(new ThreadStart(CalcPiThreadStart));
  piThread.Name = "NAME_OF_THREAD"; //TODO: Name this thread.
  piThread.Start();

But if you are trying to control this thread, keep a reference to piThread... Why are you concerned about the name of the thread?
0
 
LVL 23

Accepted Solution

by:
rama_krishna580 earned 100 total points
ID: 10902084
in that case try this one...

http://www.codeproject.com/csharp/workerthread.asp

R.K.
0
 

Author Comment

by:supertedusa
ID: 10902145
Actually, if you read on in the example, he switches to using delegates and BeginInvoke/Invoke instead of the Thread calls.

I'm concerned about the name because I want to make it easier to determine what's going on while I'm debugging this thing.

Thanks,

MT
0
 

Author Comment

by:supertedusa
ID: 10902188
Thanks for the reference - not sure how I missed that one on codeproject, but I've obviously been implementing BeginInvoke incorrectly and getting lucky in the process.

Thanks for everyone's comments.

MT
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now