Solved

BeginInvoke - name the thread

Posted on 2004-04-23
8
766 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

729 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