I have a class that handles events from another class. Unfortunately
these events arrive on a different thread. How can I marshal the code
execution to the thread on which the caller class was created.
'example
public class MyClass
{
private ClassWithEvents cls = new ClassWithEvents ();
public MyClass()
{
cls.Hangup += new HangupEventHand ler(cls_Hangup) ;
}
private void cls_Hangup(obje ct sender, HangupEvent e)
{
// this happens on a different thread
// it needs to be marshalled to the original thread.
}
} 20 14292
Frank,
You can't unless the thread you want to marshal to is an UI thread. If it is
you can use Control.Invoke or Control.BeginIn voke for some of the controls
created in the thread.
--
Stoitcho Goutsev (100)
"Frank Rizzo" <no**@none.co m> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. .. I have a class that handles events from another class. Unfortunately these events arrive on a different thread. How can I marshal the code execution to the thread on which the caller class was created.
'example
public class MyClass { private ClassWithEvents cls = new ClassWithEvents (); public MyClass() { cls.Hangup += new HangupEventHand ler(cls_Hangup) ; }
private void cls_Hangup(obje ct sender, HangupEvent e) { // this happens on a different thread // it needs to be marshalled to the original thread. } }
Stoitcho,
Well, that's not completely true. You could do it on a non UI thread,
but it would have to be a custom mechanism, and the thread would have to be
processing messages of some sort in a loop (like windows messages do).
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"Stoitcho Goutsev (100)" <10*@100.com> wrote in message
news:ua******** *****@TK2MSFTNG P09.phx.gbl... Frank,
You can't unless the thread you want to marshal to is an UI thread. If it is you can use Control.Invoke or Control.BeginIn voke for some of the controls created in the thread.
--
Stoitcho Goutsev (100)
"Frank Rizzo" <no**@none.co m> wrote in message news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..I have a class that handles events from another class. Unfortunately these events arrive on a different thread. How can I marshal the code execution to the thread on which the caller class was created.
'example
public class MyClass { private ClassWithEvents cls = new ClassWithEvents (); public MyClass() { cls.Hangup += new HangupEventHand ler(cls_Hangup) ; }
private void cls_Hangup(obje ct sender, HangupEvent e) { // this happens on a different thread // it needs to be marshalled to the original thread. } }
Nicholas Paldino [.NET/C# MVP] wrote: Stoitcho,
Well, that's not completely true. You could do it on a non UI thread, but it would have to be a custom mechanism, and the thread would have to be processing messages of some sort in a loop (like windows messages do).
I am open to that. Would you have some type of an example?
Regards
Frank,
Is this for COM interop, by chance?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"Frank Rizzo" <no**@none.co m> wrote in message
news:eT******** ******@TK2MSFTN GP09.phx.gbl... Nicholas Paldino [.NET/C# MVP] wrote: Stoitcho,
Well, that's not completely true. You could do it on a non UI thread, but it would have to be a custom mechanism, and the thread would have to be processing messages of some sort in a loop (like windows messages do).
I am open to that. Would you have some type of an example?
Regards
Nicholas Paldino [.NET/C# MVP] wrote: Frank,
Is this for COM interop, by chance?
Sadly, yes. I am creating a VB6-friendly wrapper around work done by
Asterisk .NET
( http://www.gotdotnet.com/codegallery...8-da800f4f84c3)
and Asterisk Java ( http://asterisk-java.sourceforge.net/) fellas. So,
the events work great while in .NET code however, when I pass on an
event to VB6 code, it doesn't work so well, because the event was
originally fired on a different thread.
Regards
Frank,
There is a better way to go about this.
What you want to do is marshal the interface pointer to the global
interface table. This will give you a cookie value (an unsigned int) which
you can store where you need to.
Then, in the event that is fired on another thread, you can get the
cookie, access the global interface table, and get a correctly marshaled
interface pointer to the VB object. Then, you can call your VB object
normally, and then release the interface from the table.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"Frank Rizzo" <no**@none.co m> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. .. Nicholas Paldino [.NET/C# MVP] wrote: Frank,
Is this for COM interop, by chance?
Sadly, yes. I am creating a VB6-friendly wrapper around work done by Asterisk .NET (http://www.gotdotnet.com/codegallery...8-da800f4f84c3) and Asterisk Java (http://asterisk-java.sourceforge.net/) fellas. So, the events work great while in .NET code however, when I pass on an event to VB6 code, it doesn't work so well, because the event was originally fired on a different thread.
Regards
Not sure who's talking about calling a COM object, as far as I understand
it, the client is a VB6 application which calls into a .NET class through
COM interop and is called back from another thread as the original callers
thread.
Willy.
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> wrote in
message news:OF******** *****@TK2MSFTNG P14.phx.gbl...
| Frank,
|
| There is a better way to go about this.
|
| What you want to do is marshal the interface pointer to the global
| interface table. This will give you a cookie value (an unsigned int)
which
| you can store where you need to.
|
| Then, in the event that is fired on another thread, you can get the
| cookie, access the global interface table, and get a correctly marshaled
| interface pointer to the VB object. Then, you can call your VB object
| normally, and then release the interface from the table.
|
| --
| - Nicholas Paldino [.NET/C# MVP]
| - mv*@spam.guard. caspershouse.co m
|
| "Frank Rizzo" <no**@none.co m> wrote in message
| news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
| > Nicholas Paldino [.NET/C# MVP] wrote:
| >> Frank,
| >>
| >> Is this for COM interop, by chance?
| >
| > Sadly, yes. I am creating a VB6-friendly wrapper around work done by
| > Asterisk .NET
| >
( http://www.gotdotnet.com/codegallery...8-da800f4f84c3)
| > and Asterisk Java ( http://asterisk-java.sourceforge.net/) fellas. So,
the
| > events work great while in .NET code however, when I pass on an event to
| > VB6 code, it doesn't work so well, because the event was originally
fired
| > on a different thread.
| >
| > Regards
|
|
My understanding is that there is a VB6 wrapper. It could be a COM
object (that is how I would do it) which makes the calls into the .NET
objects, passing itself (or another object) to be called when the event is
fired.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"Willy Denoyette [MVP]" <wi************ *@telenet.be> wrote in message
news:OS******** ******@TK2MSFTN GP14.phx.gbl... Not sure who's talking about calling a COM object, as far as I understand it, the client is a VB6 application which calls into a .NET class through COM interop and is called back from another thread as the original callers thread.
Willy.
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> wrote in message news:OF******** *****@TK2MSFTNG P14.phx.gbl... | Frank, | | There is a better way to go about this. | | What you want to do is marshal the interface pointer to the global | interface table. This will give you a cookie value (an unsigned int) which | you can store where you need to. | | Then, in the event that is fired on another thread, you can get the | cookie, access the global interface table, and get a correctly marshaled | interface pointer to the VB object. Then, you can call your VB object | normally, and then release the interface from the table. | | -- | - Nicholas Paldino [.NET/C# MVP] | - mv*@spam.guard. caspershouse.co m | | "Frank Rizzo" <no**@none.co m> wrote in message | news:%2******** ********@TK2MSF TNGP09.phx.gbl. .. | > Nicholas Paldino [.NET/C# MVP] wrote: | >> Frank, | >> | >> Is this for COM interop, by chance? | > | > Sadly, yes. I am creating a VB6-friendly wrapper around work done by | > Asterisk .NET | > (http://www.gotdotnet.com/codegallery...8-da800f4f84c3) | > and Asterisk Java (http://asterisk-java.sourceforge.net/) fellas. So, the | > events work great while in .NET code however, when I pass on an event to | > VB6 code, it doesn't work so well, because the event was originally fired | > on a different thread. | > | > Regards | |
Nicholas Paldino [.NET/C# MVP] wrote: My understanding is that there is a VB6 wrapper. It could be a COM object (that is how I would do it) which makes the calls into the .NET objects, passing itself (or another object) to be called when the event is fired.
No. It is exactly as Willy said in the parent post. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: William Stacey |
last post by:
The following code works, but I can't figure out why. I take a struct with
two members, a single byte and byte. I then marshal the whole struct to a
byte. I create a new struct (without init'ing any members) and marshal
the tmp array back to the new struct. The new struct shows the same data.
The single type is easy, that just gets copied. The byte ref type is the
interesting part. The address (i.e ref) of the original byte gets...
|
by: BilMuh |
last post by:
Hello Esteemed Developers and Esteemed Experts,
I have a background-running-thread in my application that is designed and developed at Windows Forms (.NET) by using Visual C++ .NET Standard on Windows 2000 Professional O.S.
Whenever the required job is done in that background-running-thread, I would like to Enable and Start the Timer to do the related job from the background-running-thread.
It is written in MSDN Library that "It...
|
by: Notre Poubelle |
last post by:
Hello,
I have a worker thread that needs to call a method that only works on the
main/UI thread. One way to accomplish this in managed code is to use
Control.Invoke. However, in my case I don't have a .NET UI control from
which I can call Invoke. I have tried to create a temporary, invisible
Windows form and call Invoke against this, and while this sort of worked, it
highlighted additional problems (which I have not resolved) and is...
|
by: Pierre Rouleau |
last post by:
Hi all,
When using Python 2.4.x on a Win32 box,
marshal.loads(marshal.dumps(1e66666)) returns 1.0 instead of infinity
as it should and does under Python 2.5 (also running on Win32 ).
This problem was reported in another thread here by Peter Hansen
http://groups-beta.google.com/group/comp.lang.python/browse_frm/thread/5c2b4b2a88c8df4/f216739705c9304f?lnk=gst&q=simplejson&rnum=5#f216739705c9304f
Is this considered an important enough...
|
by: sabys |
last post by:
I've been noticing a memory leak with the following sample code
snippet. Can someone please advise.
Have a C# Winforms app with the following code on a button-click
event.
private void button1_Click(object sender, System.EventArgs e)
{
IntPtr p1 = new IntPtr(-1);
string inputStr;
| |
by: Frankie |
last post by:
I have been learning about asynchronous method calls and I keep coming
across this term, "marshal" and I would like to know what it means -
specifically. AFAIKT, it means "send" but I suspect there is a bit more than
that.
Looking to online docs, MSDN talks about the System.Runtime.Interop.Marshal
class - but I don't think that's relevant to what I'm seeing. Maybe it is...
The following is an example of the sort of thing I've been...
|
by: O.B. |
last post by:
When using Marshal to copy data from a byte array to the structure
below, only the first byte of the "other" array is getting copied from
the original byte array. What do I need to specify to get
Marshal.PtrToStructure to copy the all the data into the "other"
array?
unsafe public struct DeadReckoning
{
|
by: Zac Burns |
last post by:
Greetings,
It seems that marshal.load will lock the problem if the file object
(in this case a pipe) is not ready to be read from - even if it's done
in a thread.
The use case here is in writing a scripting interface for perforce
using the -G option
(http://www.perforce.com/perforce/doc.072/manuals/cmdref/o.gopts.html#1040647).
We are using the sub process module to communicate through pipes to
|
by: yogiam |
last post by:
I have a server listening for connections. Client connects and both start streaming webcam images. This works fine as long as there is only one client connected(running as a Thread). When another client connects, the new thread starts streaming as well. The camera is accessed in a mutual exclusive way by locking which fails some times and I get AccessViolationException. Below is the code executing in the thread.
The scenario is like this :...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |