G
Guest
I have an application with a C# menu, that calls individual C programs, by
starting a thread for each call. This way the program is in one thread, and
the menu is in another thread, until they exit the program and that thread
ends.
The problem is the static data in the program, such as database buffers. If
the data is regular static data, then the database connection is retained
between calls to the program, which is good. But if the user initiates a
second menu option while the first one is running, the data is shared between
them, which is bad.
The solution to that is to make the data Thread static, like this:
#define Thread __declspec(thread)
Thread static char MyPublicData[100]="My Public Data";
This makes the data unique to each time the C program runs, so that the
database connections do not get corrupted. The problem is that it if the user
calls an option, exits, and calls another one, the data should be retained,
like regular static data. But if they call one, then call another while the
first one is still running, it should be a new set of static data, like
Thread static.
My thought was to use a thread for a program, then reuse the same thread
again for the second call that came after the first one ended. If the user
ran two at once, I would initialize a second thread. But when I try and reuse
a thread, I get an error, that the thread is dead. I reused it simply by
running
RThread.Start();
A second time, where
Thread RThread = new Thread();
So my question is, is there a way to reuse the thread after it has ended, so
that I can preserve the data from call to call sometimes, but not at other
times? Thanks for any suggestions.
starting a thread for each call. This way the program is in one thread, and
the menu is in another thread, until they exit the program and that thread
ends.
The problem is the static data in the program, such as database buffers. If
the data is regular static data, then the database connection is retained
between calls to the program, which is good. But if the user initiates a
second menu option while the first one is running, the data is shared between
them, which is bad.
The solution to that is to make the data Thread static, like this:
#define Thread __declspec(thread)
Thread static char MyPublicData[100]="My Public Data";
This makes the data unique to each time the C program runs, so that the
database connections do not get corrupted. The problem is that it if the user
calls an option, exits, and calls another one, the data should be retained,
like regular static data. But if they call one, then call another while the
first one is still running, it should be a new set of static data, like
Thread static.
My thought was to use a thread for a program, then reuse the same thread
again for the second call that came after the first one ended. If the user
ran two at once, I would initialize a second thread. But when I try and reuse
a thread, I get an error, that the thread is dead. I reused it simply by
running
RThread.Start();
A second time, where
Thread RThread = new Thread();
So my question is, is there a way to reuse the thread after it has ended, so
that I can preserve the data from call to call sometimes, but not at other
times? Thanks for any suggestions.