Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

BeginInvoke - name the thread

Posted on 2004-04-23
8
Medium Priority
?
768 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
Technology Partners: 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 400 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

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…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

604 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