PC Review


Reply
Thread Tools Rate Thread

Access Control In a Form From Library Function on Worker Thread

 
 
joey.powell@topscene.com
Guest
Posts: n/a
 
      5th Apr 2006
I have a windows forms app with a statusbar. In the form's code, I use
a delegates and spawn a worker thread to get processing off of the GUI
thread. Then in the worker thread I access a function in a library
file. The function needs to be able to update some of the forms status
bar panels. I have had great success in doing the following...

Invoke(new UpdateStatusDelegate(this.UpdateStatus), new object[] { "My
Message" });


BUT, it doesn't work from the function in the library file. I have
gotten it down to two error messages on compile:


1. The name 'Invoke' does not exist in the current context
2. An object reference is required for the nonstatic field, method, or
property 'MyNamespace._MyFormInstance.UpdateStatus(string)'


First, I do not understand why the first error message is occurring. I
have all "using" statements in the library file set to the same as in
the form's code file. I am missing something, somewhere.


Second, I can see why the second message is occurring. The calling form

instance is non-static. But this doesn't cause any problem when using
the code snippet in the form's code file.


Any suggestions?

 
Reply With Quote
 
 
 
 
Bob Powell [MVP]
Guest
Posts: n/a
 
      5th Apr 2006
I suspect that you've made the handler, from which you invoke the call, a
static method.. Therefore in that context there is no "this."

The thread's event handler should have an instance of the form, check to see
if invoke is required (it normally is but you never know) and invoke the
method directly from the handler.
--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.



<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I have a windows forms app with a statusbar. In the form's code, I use
> a delegates and spawn a worker thread to get processing off of the GUI
> thread. Then in the worker thread I access a function in a library
> file. The function needs to be able to update some of the forms status
> bar panels. I have had great success in doing the following...
>
> Invoke(new UpdateStatusDelegate(this.UpdateStatus), new object[] { "My
> Message" });
>
>
> BUT, it doesn't work from the function in the library file. I have
> gotten it down to two error messages on compile:
>
>
> 1. The name 'Invoke' does not exist in the current context
> 2. An object reference is required for the nonstatic field, method, or
> property 'MyNamespace._MyFormInstance.UpdateStatus(string)'
>
>
> First, I do not understand why the first error message is occurring. I
> have all "using" statements in the library file set to the same as in
> the form's code file. I am missing something, somewhere.
>
>
> Second, I can see why the second message is occurring. The calling form
>
> instance is non-static. But this doesn't cause any problem when using
> the code snippet in the form's code file.
>
>
> Any suggestions?
>



 
Reply With Quote
 
joey.powell@topscene.com
Guest
Posts: n/a
 
      5th Apr 2006
Bob, I'm sorry but I don't quite understand. The worker thread was
spawned in the form's code file, and then there it calls a function in
a different library (.cs file). As far as I can tell, there is no
"handle" to grab from within the library file. I have used...

MyNameSpace.MyFormName.ActiveForm.Invoke to get rid of the Invoke error
message, but I still can't compile because of the second error message,
and so I don't know if that worked.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing Objects Into Worker Thread Function joey.powell@topscene.com Microsoft C# .NET 14 27th Jul 2006 10:03 AM
Sending commands to a worker thread from a form control??? Ole Microsoft Dot NET Compact Framework 1 29th May 2006 01:07 PM
Raise event from library worker thread. Johan Microsoft Dot NET Compact Framework 3 8th Jul 2003 02:06 PM
Re: Raise event from library worker thread. Alex Feinman [MVP] Microsoft VC .NET 1 7th Jul 2003 10:53 PM
Raise event from library worker thread. Johan Microsoft Dot NET Framework 2 7th Jul 2003 10:53 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:14 PM.