Hello -
I was wondering if there is a simple way of ensuring that some
statements are executed as an "atomic operation". Here is what I am
dealing with in a GUI ...
Dim mAppDomain As AppDomain
The following sets the mAppDomain in a function ...
mAppDomain = AppDomain.Creat eDomain(lFullPa thAssembly)
.... and does other stuff with it ...
The problem is when for whatever reason the GUI is closed while the
above is running and the above causes an exception that sets the
mAppDomain to Nothing.
Protected Overrides OnClosing(...)
If Not (mAppDomain Is Nothing) Then
AppDomain.Unloa d(mAppDomain)
mAppDomain = Nothing
End If
...
What could potentially happen is that the mAppDomain is set to Nothing
between the If Not () Then and the Unload() call.
Is there a way to make the If() and Unload() calls atomic so that
nothing else can be done with mAppDomain in between those calls?
Thanks!
Joe 7 3608
I was wondering if there is a simple way of ensuring that some
statements are executed as an "atomic operation". Here is what I am
dealing with in a GUI ...
Dim mAppDomain As AppDomain
The following sets the mAppDomain in a function ...
mAppDomain = AppDomain.Creat eDomain(lFullPa thAssembly)
.... and does other stuff with it ...
The problem is when for whatever reason the GUI is closed while the
above is running and the above causes an exception that sets the
mAppDomain to Nothing.
Protected Overrides OnClosing(...)
If Not (mAppDomain Is Nothing) Then
AppDomain.Unloa d(mAppDomain)
mAppDomain = Nothing
End If
...
What could potentially happen is that the mAppDomain is set to Nothing
between the If Not () Then and the Unload() call.
Is there a way to make the If() and Unload() calls atomic so that
nothing else can be done with mAppDomain in between those calls?
There is no way to make them atomic in the sense you mean. You have two
choices. First, you can guard mAppDomain with a mutex. In all places in
code where mAppDomain is referenced, acquire the mutex, do your thing, and
release the mutex. Second, you could put the code you are worried about in a
Try-Catch block, and if the exception is the null reference exception, you
ought to be able to clean up in Catch without causing any downstream problems.
Joe HM wrote:
I was wondering if there is a simple way of ensuring that some
statements are executed as an "atomic operation".
What could potentially happen is that the mAppDomain is set to Nothing
between the If Not () Then and the Unload() call.
Is there a way to make the If() and Unload() calls atomic so that
nothing else can be done with mAppDomain in between those calls?
The "Visual Basic" way is to use the SyncLock keyword.
The full-blown Framework'y way would be a Mutex object.
HTH,
Phill W.
Hello -
Yeah ... I figured I could use Try/Catch in that case. I will look
into it some more and maybe use a Mutex if necessary.
Thanks guys!
Joe
AMercer wrote:
There is no way to make them atomic in the sense you mean. You have two
choices. First, you can guard mAppDomain with a mutex. In all places in
code where mAppDomain is referenced, acquire the mutex, do your thing, and
release the mutex. Second, you could put the code you are worried about in a
Try-Catch block, and if the exception is the null reference exception, you
ought to be able to clean up in Catch without causing any downstream problems.
"Joe HM" <un*******@yaho o.comschrieb:
I was wondering if there is a simple way of ensuring that some
statements are executed as an "atomic operation". Here is what I am
dealing with in a GUI ...
Dim mAppDomain As AppDomain
The following sets the mAppDomain in a function ...
mAppDomain = AppDomain.Creat eDomain(lFullPa thAssembly)
... and does other stuff with it ...
The problem is when for whatever reason the GUI is closed while the
above is running and the above causes an exception that sets the
mAppDomain to Nothing.
Protected Overrides OnClosing(...)
If Not (mAppDomain Is Nothing) Then
AppDomain.Unloa d(mAppDomain)
mAppDomain = Nothing
End If
...
What could potentially happen is that the mAppDomain is set to Nothing
between the If Not () Then and the Unload() call.
Is there a way to make the If() and Unload() calls atomic so that
nothing else can be done with mAppDomain in between those calls?
\\\
Private m_LockObject As New Object()
Protected Overrides Sub OnClosing(...)
SyncLock m_LockObject
If Not (mAppDomain Is Nothing) Then
AppDomain.Unloa d(mAppDomain)
mAppDomain = Nothing
End If
End SyncLock
End Sub
///
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Joe HM wrote:
Hello -
I was wondering if there is a simple way of ensuring that some
statements are executed as an "atomic operation".
Use SyncLock or Monitor.Enter and Monitor.Exit.
Here is what I am dealing with in a GUI ...
Dim mAppDomain As AppDomain
The following sets the mAppDomain in a function ...
mAppDomain = AppDomain.Creat eDomain(lFullPa thAssembly)
... and does other stuff with it ...
Where is this executing? I'm assuming it's on a thread other than the
main UI thread. Is that correct?
The problem is when for whatever reason the GUI is closed while the
above is running and the above causes an exception that sets the
mAppDomain to Nothing.
Protected Overrides OnClosing(...)
If Not (mAppDomain Is Nothing) Then
AppDomain.Unloa d(mAppDomain)
mAppDomain = Nothing
End If
...
What could potentially happen is that the mAppDomain is set to Nothing
between the If Not () Then and the Unload() call.
The only way that could happen is if the previous code snippet you
provided is executing on another thread.
Is there a way to make the If() and Unload() calls atomic so that
nothing else can be done with mAppDomain in between those calls?
Yes, you must wrap both code snippets with a lock by using the SyncLock
keyword. Its not guarenteed to work if you only wrap the contents of
the OnClosing method.
Thanks!
Joe
Phill W. wrote:
Joe HM wrote:
The "Visual Basic" way is to use the SyncLock keyword.
The full-blown Framework'y way would be a Mutex object.
HTH,
Phill W.
Phill,
Actually, SyncLock is the "full-blown Framework'y" way of doing it. A
Mutex is typically used to synchronize access to a resource shared by
multiple processes.
Brian
Hello -
Thanks for the feedback. Yes ... I am using multiple threads. I will
give SyncLock or Monitor.Enter/Exit a try.
Thanks!
Joe
Brian Gideon wrote:
Joe HM wrote:
Hello -
I was wondering if there is a simple way of ensuring that some
statements are executed as an "atomic operation".
Use SyncLock or Monitor.Enter and Monitor.Exit.
Here is what I am dealing with in a GUI ...
Dim mAppDomain As AppDomain
The following sets the mAppDomain in a function ...
mAppDomain = AppDomain.Creat eDomain(lFullPa thAssembly)
... and does other stuff with it ...
Where is this executing? I'm assuming it's on a thread other than the
main UI thread. Is that correct?
The problem is when for whatever reason the GUI is closed while the
above is running and the above causes an exception that sets the
mAppDomain to Nothing.
Protected Overrides OnClosing(...)
If Not (mAppDomain Is Nothing) Then
AppDomain.Unloa d(mAppDomain)
mAppDomain = Nothing
End If
...
What could potentially happen is that the mAppDomain is set to Nothing
between the If Not () Then and the Unload() call.
The only way that could happen is if the previous code snippet you
provided is executing on another thread.
Is there a way to make the If() and Unload() calls atomic so that
nothing else can be done with mAppDomain in between those calls?
Yes, you must wrap both code snippets with a lock by using the SyncLock
keyword. Its not guarenteed to work if you only wrap the contents of
the OnClosing method.
Thanks!
Joe
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Paul Moore |
last post by:
I can't find anything which spells this out in the manuals. I guess
that, at some level, the answer is "a single bytecode operation", but
I'm not sure that explains it for me.
This thought was triggered by a comment on the Python Cookbook site,
which basically said that it was OK to do
tss = {}
...
id = thread.get_ident()
tss = {}
|
by: Shayan |
last post by:
Is there a boolean flag that can be set atomically without needing to
wrap it in a mutex? This flag will be checked constantly by multiple
threads so I don't really want to deal with the overhead of mutexes or
semaphores. Thanks.
Shayan
|
by: Zeng |
last post by:
Hello,
Is the assignment operation atomic? That is if one thread assigns to static
variable an object and another uses the object assigned to the variable,
would it be safe?
Thanks!
zeng
|
by: blackstreetcat |
last post by:
consider this code :
int i; //gobal var
Thread1:
i=some value;
Thread2:
if (i==2) dosomething();
else dosomethingelse();
|
by: spacehopper_man |
last post by:
no "rename" operation in C# !!!
- this has been covered in this group before, but I can't find any good
answers.
what I am trying to do is refresh the content in a file with minimum
performance impact on any read operations to that file - a common task
right....
in the unix world the way to do this is to create a temporary file with
| |
by: japhy |
last post by:
Is there a way to read a line (a series of characters ending in a
newline) from a file (either by descriptor or stream) atomically,
without buffering additional contents of the file?
|
by: Freedom fighter |
last post by:
Hello,
Is a singleton class the same as an atomic class? I know that a singleton class
can only be instantiated once, but does that concept apply to an atomic class?
Thank you.
|
by: Dmitriy V'jukov |
last post by:
On 16 ÍÁÊ, 21:41, "Dmitriy V'jukov" <dvyu...@gmail.comwrote:
According to definition, release operation on
'std::atomic_global_fence_compatibility' can only 'synchronize with'
acquire operation on 'std::atomic_global_fence_compatibility'.
Imho, it's a bit senseless. I think that I miss something. Can
somebody clarify about std::atomic_global_fence_compatibility?
|
by: Jon Harrop |
last post by:
Can read locks on a data structure be removed safely when updates are
limited to replacing a reference? In other words, is setting a reference an
atomic operation?
I have been assuming that all writes of <=1 word of data are atomic. Is this
actually documented anywhere?
--
Dr Jon D Harrop, Flying Frog Consultancy
http://www.ffconsultancy.com/products/?u
|
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: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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: 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.
| |