Solved

BeginInvoke - name the thread

Posted on 2004-04-23
8
762 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

 

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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Device Location 4 36
Reading the Web.Config using IIS 7.5? 4 49
Create a WebAPI using a generic return parameter 9 32
RegEx with optional part 4 42
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

821 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