473,378 Members | 1,360 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,378 software developers and data experts.

problem regarding threads, invoke and class libraries

Hi,
I have a class library with some classes... One of those classes fire
events from a different thread. When I try to display the information
contained in the event args of this event in my UI, it says I can't access
my control's properties from a different thread... I wanted to use the
Invoke() method, but it's not available in my class nor in my thread... What
is the solution to this? I mean, how can I raise events like all others do,
in-proc with the form's thread?

thanks

ThunderMusic
Aug 2 '06 #1
2 1048
ThunderMusic <No*************************@NoSpAm.comwrote:
I have a class library with some classes... One of those classes fire
events from a different thread. When I try to display the information
contained in the event args of this event in my UI, it says I can't access
my control's properties from a different thread... I wanted to use the
Invoke() method, but it's not available in my class nor in my thread... What
is the solution to this? I mean, how can I raise events like all others do,
in-proc with the form's thread?
You need to call Invoke on a UI element. (Or anything else implementing
ISynchronizeInvoke appropriately.)

See http://www.pobox.com/~skeet/csharp/t...winforms.shtml for more
information.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Aug 2 '06 #2
I'm actually not using any form in my class library, so I don't want users
of the library to call invoke on their controls each time they receive the
events... anyway, I just found the solution... I found it there :

http://www.codeproject.com/csharp/invoke_other_way.asp

it's at about half of the page...

I hope it can help someone else... ;)

Thanks for the quick answer tought...

ThunderMusic

"Jon Skeet [C# MVP]" <sk***@pobox.comwrote in message
news:MP************************@msnews.microsoft.c om...
ThunderMusic <No*************************@NoSpAm.comwrote:
>I have a class library with some classes... One of those classes fire
events from a different thread. When I try to display the information
contained in the event args of this event in my UI, it says I can't
access
my control's properties from a different thread... I wanted to use the
Invoke() method, but it's not available in my class nor in my thread...
What
is the solution to this? I mean, how can I raise events like all others
do,
in-proc with the form's thread?

You need to call Invoke on a UI element. (Or anything else implementing
ISynchronizeInvoke appropriately.)

See http://www.pobox.com/~skeet/csharp/t...winforms.shtml for more
information.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Aug 2 '06 #3

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

Similar topics

4
by: Eric | last post by:
Hi, can anyone guide me throught this: In my application, I have a global DataSet. I then run FTP processes in up to 10 simultaneous threads and each thread calls progress events in the main...
12
by: Grant | last post by:
I am having great difficulty understanding this and any code samples I find online are kilometres long and complicated to understand...Please could someone give me a simple exampe of how to get a...
1
by: Chuck | last post by:
I am creating a pub/sub broker implementation in C# and I am having some trouble understanding how I should best implement the invoke portion in order to make sure it is as thread-safe as it can...
2
by: Joerg M. Colberg | last post by:
I have a VS.Net solution that contains various projects. Some of the projects contain programme blocks (legacy code) that are used by some of the other projects. One project contains some C code...
0
by: Andy Roxburgh | last post by:
Hi all, I'm trying to program a multithreaded application - it currently works, but I have two problems. I'm relatively new to VB.NET (C and VB6 are my things) so I'm a bit lost here. The code...
3
by: archana | last post by:
Hi all, I have one confusion regarding threading in windows service which is developed in c#. What i am doing is on 'onstart' event i am starting one thread. In thread procedure i am...
2
by: ThunderMusic | last post by:
Hi, I have a class library with some classes... One of those classes fire events from a different thread. When I try to display the information contained in the event args of this event in my UI,...
4
by: Jon Harrop | last post by:
I'm trying to define a Show3D class that takes a scene graph and spawns a visualization rendering that scene graph in a new thread but keeps it editable via properties in the Show3D class. For...
4
by: cyrous xiao | last post by:
I hvae three thread and a thread that is used to show a winform. The code: Thread ThreadDialog= new Thread (new ThreadStart (ShowDialog)); //Show a winform Dialog ThreadDialog.Start ();...
2
by: =?Utf-8?B?VHJlY2l1cw==?= | last post by:
Hello, Newsgroupians: I have a question regarding threads changing the UI of a form. I have an external device that sends signals to my application by using their library. To do this, all I...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.