473,320 Members | 1,881 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Access Control In a Form From Library Function on Worker Thread

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?

Apr 5 '06 #1
2 2826
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.

<jo*********@topscene.com> wrote in message
news:11**********************@z34g2000cwc.googlegr oups.com...
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?

Apr 5 '06 #2
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.

Apr 5 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Paul Shave | last post by:
In an MDI app, from a child form I use BeginInvoke on a delegate to start an async printing process. When it finishes, my callback function (on the worker thread) calls me.BeginInvoke to get back...
5
by: Stephen Lamb | last post by:
I have a background worker thread which I start from a form's HandleCreated event that makes calls back to the form using Invoke. During shutdown the form is disposed and the background worker...
3
by: Brian Keating EI9FXB | last post by:
Hello again, I've already placed a few posts on this topic. This time i've a simple application that exhibits my problem, I've placed sample solution 8k on my website should anyone be interested...
3
by: [Yosi] | last post by:
I have some unreasonable issue while reading access component from other thread. I have a Form class which includes TreeView, this tree view includes some TreeNodes , lets say 2 . In my Form...
4
by: Daylor | last post by:
hi. i have multi thread application in vb.net is there a way NET support, so i can mark the class , to be access only for 1 thread each time ? if there is , small sytax sample will help ...
1
by: Mamatha | last post by:
Hi I have a small application in VB.NET,it consists of one form,one class and one module.I have declared one thread globally in module to execute the function in the form.I started that thread...
3
by: nmanausa | last post by:
I am programming an Access database for a blind co-worker. I need to plug in a DLL, but I've never done it before. Here's all the information that is available (after hours of Googling): ...
3
by: Peted | last post by:
Hi i hope i explaine this correctly I have a class with a method that reads and writes using blocking sockets to a TCP device. Call it class IPdevice. I can use this method to send commands and...
3
by: stumorgan | last post by:
Basically what I have is a form with a graph on it which graphs data that I'm reading from a USB device at 100 Hz (every 10ms). I have a thread reading and parsing the data from the USB, but when...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.