Hi,
I use a delegate to call a method from my main GUI thread. This delegate
takes one of my business objects as a parameter. When I do a synchronous
call, it all works fine, but if I do an async call like:
delegate.BeginI nvoke( myBusinessObjec t, callBackDelegat e, delegate );
and I debug into the called method, I find that myBusinessObjec t is
partially corrupt. All basic type members, like strings etc. are fine, but
my reference members to other objects from the original thread are
non-existent anymore and the debugger cannot resolve them. When I check the
object on the caller's side, i.e. right after the BeginInvoke call, it is
fine, too.
I checked the MSDN, but they always use plain old datatypes as examples.
Maybe it only works for them?
If anyone could enlighten me, why my objects are corrupt, I would be very,
very grateful.
Thanks,
Marc. 2 1914
Marc,
I don't think they become corrupt because of anything that the CLR is
doing. It ^could^ be an issue with the debugger, and the fact that you are
jumping threads. However, the possiblity exists that something else is
making calls to the object on more than one thread at a time, causing the
corruption.
Are you sure you aren't modifying the object after you pass the
reference to the delegate to be invoked asynchronously?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"Marc Bartsch" <m.*******@rdg. ac.uk> wrote in message
news:uS******** ****@newsfe3-win.ntli.net... Hi,
I use a delegate to call a method from my main GUI thread. This delegate takes one of my business objects as a parameter. When I do a synchronous call, it all works fine, but if I do an async call like:
delegate.BeginI nvoke( myBusinessObjec t, callBackDelegat e, delegate );
and I debug into the called method, I find that myBusinessObjec t is partially corrupt. All basic type members, like strings etc. are fine, but my reference members to other objects from the original thread are non-existent anymore and the debugger cannot resolve them. When I check the object on the caller's side, i.e. right after the BeginInvoke call, it is fine, too.
I checked the MSDN, but they always use plain old datatypes as examples. Maybe it only works for them?
If anyone could enlighten me, why my objects are corrupt, I would be very, very grateful.
Thanks,
Marc.
Hi,
Thanks for your answer.
It just turned out that a wrong mutex.WaitOne() was responsible for it.
Whenever I stayed within the same thread, the wrong mutex.WaitOne() would
not matter, but in a different thread, it would freeze that thread. Since
the thread was frozen, the debugger could not resolve all my members. ;-)
Thanks anyway,
Marc.
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> schrieb
im Newsbeitrag news:Oq******** *****@TK2MSFTNG P15.phx.gbl... Marc,
I don't think they become corrupt because of anything that the CLR is doing. It ^could^ be an issue with the debugger, and the fact that you are jumping threads. However, the possiblity exists that something else is making calls to the object on more than one thread at a time, causing the corruption.
Are you sure you aren't modifying the object after you pass the reference to the delegate to be invoked asynchronously?
-- - Nicholas Paldino [.NET/C# MVP] - mv*@spam.guard. caspershouse.co m
"Marc Bartsch" <m.*******@rdg. ac.uk> wrote in message news:uS******** ****@newsfe3-win.ntli.net... Hi,
I use a delegate to call a method from my main GUI thread. This delegate takes one of my business objects as a parameter. When I do a synchronous call, it all works fine, but if I do an async call like:
delegate.BeginI nvoke( myBusinessObjec t, callBackDelegat e, delegate );
and I debug into the called method, I find that myBusinessObjec t is partially corrupt. All basic type members, like strings etc. are fine, but my reference members to other objects from the original thread are non-existent anymore and the debugger cannot resolve them. When I check the object on the caller's side, i.e. right after the BeginInvoke call, it is fine, too.
I checked the MSDN, but they always use plain old datatypes as examples. Maybe it only works for them?
If anyone could enlighten me, why my objects are corrupt, I would be very, very grateful.
Thanks,
Marc.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Tony Johansson |
last post by:
Hello Experts!
What does this mean actually.
If you have a template with a type and non-type template argument, say, like
this
template<typename T, int a>
class Array {. . .};
then A<int, 1> and A<int, 2> are different types. Now, if the A template
|
by: arkam |
last post by:
Hi,
I found a sample on internet :
formMain.BeginInvoke(new MyClickHandler(this.OnMyClick));
I would like to do the same but in a class library where there is no forms !
Where can I find a BeginInvoke equivalent for a class library ?
|
by: Alex Zhitlenok |
last post by:
I found out that if you subscribe to or unsubscribe from an event in
the method that gets event handler as a parameter, it does not work as
expected.
If the event is declared as
event MyEventHandler myEventHandler;
you can subscribe to the event, using the construction
myEventHandler += subscriber;
but you cannot do the same by sending event handler as a parameter to
a method of the same class.
|
by: Valerie Hough |
last post by:
I'm not entirely sure what the difference is between these two approaches.
In order to avoid reentrant code, I was using Control.BeginInvoke in my UI
to cause an asynchronous activity to be done on the UI's message loop. I
began to get System.ExecutionEngineException errors so (on the theory of do
something different if what you're doing isn't working) I switched to using
delegate.BeginInvoke with the appropriate EndInvoke and the problem...
|
by: JohnnyGr |
last post by:
I have heard theres a new way to start threads with parameters in
framework 2.0, does anyone know how to do that?
this is what i need to do...
Start a thread that executes some stuff, in this case it does gets all
files from a directory. then i need to update the GUI with information
from the thread...
the thread should be started with a parameter, in this case its a string
| |
by: Malcolm |
last post by:
Hi. I am attempting something new in my coding and need some direction. I
have a web service that I am attempting to return a custom colleciton of
custom objects of a single type.
When I call the web method from a client host I am getting back a
1-dimensional array and I can't convert each item in the array to the
appropriate custom type that is exposed in the array.
Can any body provide me some direction on how I should be passing...
|
by: RWF |
last post by:
I have a windows form of which I will be saving the user's selections from
DropDownBoxes, CheckBoxes, and RadioButtons. Once the choices are collected,
I really will have no use for any of the controls. Is there a benefit of
using Control.BeginInvoke opposed to ThreadPool.QueueWorkItem? From the
threads I have briefly scanned over on the www, there really is no difference
other. Some have mentioned that ThreadPool.QueueWorkItem maybe...
|
by: fniles |
last post by:
How can I call BeginInvoke for a sub that has a parameter ?
I have a sub WriteInput that change the Text field txtInput with the value
passed in its parameter.
How can I call WriteInput using BeginInvoke ?
The following codes gave me "parameter count mismatch" error.
Public Delegate Sub WriteLineDelegate2(ByVal data() As Object)
Public Sub WriteInputGL(ByVal data() As Object)
|
by: chris.spano |
last post by:
I'm running Access 2003 on an XP machine, and there are multiple
developers who are working on different "assignments" of our large
database project. We all work on a local copy and export changes made
to various objects. Version controlling is becoming more of an issue,
so we've developed a real basic version control system that tracks
"exports" to the primary DB (which is then version-controlled prior to
distribution to the client--which...
|
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: 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: 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: 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: 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
| |
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...
| |