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 generally
not a very clean solution.
If I were writing in unmanaged code, I would likely use
CoMarshalInterT hreadInterfaceI nStream. I could also post a message back to
the main thread. Is something like this possible in managed code or are
there ways other than Control.Invoke to pass an interface pointer to a
different thread?
One other potential challenge is that my code is not responsible for
starting the secondary thread; it is started by the framework in which my
code executes. For a detailed discussion of what exactly I'm trying to
accomplish, see http://groups.google.ca/group/micros...3ce7d2f03e67e3.
Thanks!
Notre
Dec 12 '05
14 6964
Notre,
In that thread on Joel's form, I was talking about creating an
implementation of ISynchronizeInv oke for worker threads. I'm not sure
that would help your current problem, however, as you are trying to
marshall back to the main ui thread.
If you are using .NET 2.0, I think that there is some static class that
lets you marshall to the main ui thread without a Control. I haven't
gotten to play much with 2.0, but I remember stumbling on something
like that when I was trying 2.0 out... I'm taking a breif look at
MSDN2, but I can't seem to find it right now.
Sean
Notre Poubelle wrote: Hi Charles,
Thanks for the response and the link. I did review the reference, but to be quite honest I don't know if I followed everything that was said there.
I'm not sure if I could implement the ISynchronizeInv oke interface. The only implementation I could find of this was in System.Windows. Forms.Control. I started to look at the Invoke method with a disassembler, but got lost in all the details. I'd hate to have to redo all the work MS did in implementing this, although maybe that's the only way, short of creating a temporary form and (somehow) resolving the other problems that I've run into using that approach.
Notre
Hi Sean,
Thanks for your reply. I am using .NET 2.0, so if such a static class does
exist, it would be perfect for my needs! I'll have a look around in the docs
and if I can't find it, I'll start a new discussion thread to see if anyone
else knows about it.
Notre
Hi Notre
I think, as has probably been said elsewhere, the reason why forms and
controls can be so readily interrupted is that they have a message loop. If
we are just talking about a bespoke class then, unless it has an idle
period, it cannot be interrupted. The class would have to, periodically,
look for some signal that another process was trying to do stuff. If it is a
worker thread then it could explicitly look for a signal each time round its
processing loop.
Charles
"Notre Poubelle" <no************ @online.nospam> wrote in message
news:B7******** *************** ***********@mic rosoft.com... Hi Charles,
Thanks for the response and the link. I did review the reference, but to be quite honest I don't know if I followed everything that was said there.
I'm not sure if I could implement the ISynchronizeInv oke interface. The only implementation I could find of this was in System.Windows. Forms.Control. I started to look at the Invoke method with a disassembler, but got lost in all the details. I'd hate to have to redo all the work MS did in implementing this, although maybe that's the only way, short of creating a temporary form and (somehow) resolving the other problems that I've run into using that approach.
Notre
Hi Sean
I am having the same problem: i need to raise events from worker thread
to the main thread(not UI thread) in the main thread's context.
The static class that was suggested earlier is probably:
Synchronization Context that works perfectly with the UI thread but ONLY
with it(probably because it works with the windows message queue and
worker threads does not have that). although docs mentioned otherwise.
BTW BackgroundThrea d uses this class so it also good only for UI main
threads.
Other thoughts i am having are:
1)implementing message pump for the worker thread so it could receive
windows messages
2)Poll shared queue for incomming messages from the worker thread(i'd
hate to do that since i want the user to be free of that)
I will be more then happy to hear if u found any other solution since i
am frustrated about this situation.
Regards
Shay
*** Sent via Developersdex http://www.developersdex.com *** This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: awk |
last post by:
Hi All
I have a com dll written in VB6 (it's a User Function Library for my crystal
reports - this allows me to write custom functions for Crystal
which can be applied in Crystal formulas - none of this is relevant to the
problem though (((I think)))).
Anyway, the VB dll has one method that takes a string as an argument and
returns a string. It passes the string arg to a C# library
which is where the problem lies. The string arg...
|
by: Paul |
last post by:
I'm porting a C++ function which reads a file in binary mode, sometimes
reading 2 bytes into an unsigned short, 4 bytes into a long, etc into a C#
implementation. When using the FileStream.Read function, I'd like to code
it to read the size of a C# ushort, for example. The documentation says the
sizeof() is only supported in unsafe mode. Is there any equivalent to
sizeof() that I can use in managed code?
|
by: nygiantswin2005 |
last post by:
I would like to know how do I pass a pointer to a struct from managed
code to unmanaged code. For example if I create structure like this in
managed code.
StructLayout( LayoutKind.Sequential, CharSet=CharSet.Ansi ) ]
public struct MYSTRUCT
{
public String Text;
|
by: Johannes Unfried |
last post by:
Problem
Best practice needed to marshal STL data from managed code to unmanaged code & vice vers
Details
managed code is written in managed C++ & accesses the unmanaged code (i.e. lives in a mixed mode DLL
unmanaged code is written in unmanaged C++ & resides in an unmanaged DL
Product used is VS.NET 200
Please tell me what is the best practice for getting and setting data fro
unmanaged to managed part when I have a class with...
|
by: Daren Hawes |
last post by:
Hi,
My web host has a low security setting on the shared .net server I use. I
cannot use third party dll's or install assemblies in the GAC.
All I need to do is verify that a FTP login is true. I do not need to move
files etc, simply check if the ftp details that were collected in a web form
actually authenticate with the remote ftp server. Can this be completed
using managed code only?
| |
by: kimberly.walker |
last post by:
Im very new to coding in C++ so use to coding in C#. My question is
how to pass some values (string) from unmanaged code to managed code. I
have two source files on a win32 console application one I used #pramga
managed to change to managed code but I need to get the values from the
unmanaged code and pass it to the managed code. Thanks...
|
by: Ananas |
last post by:
Hi,
My native C++ function creates a dynamic array. I'm marshalling it to
managed code and got to delete after. How to make it:
c++ code:
void CreateArrayInside( pTestStruct &TestStruct,
unsigned int &size)
{
|
by: =?Utf-8?B?UmF2aSBTaGFua2Fy?= |
last post by:
Hi,
I have a requirement where I need to call methods written in VB.Net from a
C++ code. I have been going crazy reading various articles on the net w.r.t
interop and marshalling but an more confused now that before.
the signature I need to conform in the VB.Net DLL is
int MyAppInitFunc(int argc, char** argv)
To this extent I have tried the following
|
by: oleop |
last post by:
I am trying to call dll from the managed code.eveyrting works OK until i'm trying to use fucntions that use complex (containing arrays of structures) structures as a parameters.
Let's say
private static extern int myFunc(ref STRUCT2 someStrust);
|
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: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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
| |