Click here to Skip to main content
15,917,604 members
Home / Discussions / C#
   

C#

 
AnswerRe: join Pin
tom57200715-Apr-09 2:53
tom57200715-Apr-09 2:53 
Questionproblem in setting backround image to a form created using OpenGL in c# Pin
raesa15-Apr-09 1:34
raesa15-Apr-09 1:34 
Questionhow to write string in PDF Pin
wasimsharp15-Apr-09 1:10
wasimsharp15-Apr-09 1:10 
AnswerRe: how to write string in PDF Pin
stancrm15-Apr-09 1:18
stancrm15-Apr-09 1:18 
GeneralRe: how to write string in PDF Pin
wasimsharp15-Apr-09 18:23
wasimsharp15-Apr-09 18:23 
AnswerRe: how to write string in PDF Pin
tom57200715-Apr-09 2:56
tom57200715-Apr-09 2:56 
Questionmultithreading: lock (static) function library Pin
rpm820015-Apr-09 0:58
rpm820015-Apr-09 0:58 
AnswerRe: multithreading: lock (static) function library Pin
Moreno Airoldi15-Apr-09 3:22
Moreno Airoldi15-Apr-09 3:22 
I don't know the details of your implementation, but I guess you're using Windows Forms.
Remember that having more than one open Form open doesn't mean they are running on different threads.
So I will give it for granted that you are running your communications code in two separate threads you created.

I guess your function library exposes functions to start the communications and callback events to signal the end of communications or errors (timeout, wrong response, etc.). You should use lock in your library's functions (or in calls to those functions, if you don't want to modify the library) in order to achieve a first level of thread-safety, but this won't solve the problem of not having the two threads trying to communicate to the same device at the same time if the communication is in progress between calls to the various library functions (i.e. if it is asynchronous). If the communication is synchrnonous, it will be enough.

If the communication is asynchronous, using thread locking to avoid concurrent access to the devices is usually not a good practice, since communications can take a long time (especially when checking timeouts), and you would keep you threads locked during all that time, thus losing all the benefits of async comms.

In that case, you should implement a (thread-safe) queue of requests coming from the two threads. Each request will be satisfied when the instrument is "free" and the result posted in another (thread-safe) queue or sent to the calling thread by means of events or similar. All this can be implemented in a "controller" class, which will stand between your calling threads and your library. The controller might also use a simple round-robin system (with priority management, if you need it) to manage access to the library.

If you want to be more OO, you can also create a class for each type of instrument and create instances for every physical instrument. These classes will expose properties and functions to read and write the desired values to/from the devices, and will stand between your calling threads and the controller class.

Hope this can be of some help.

2+2=5 for very large amounts of 2
(always loved that one hehe!)

AnswerRe: multithreading: lock (static) function library Pin
PIEBALDconsult15-Apr-09 6:29
mvePIEBALDconsult15-Apr-09 6:29 
GeneralRe: multithreading: lock (static) function library Pin
rpm820015-Apr-09 22:56
rpm820015-Apr-09 22:56 
QuestionSQL Script Pin
kibromg15-Apr-09 0:54
kibromg15-Apr-09 0:54 
AnswerRe: SQL Script Pin
tom57200715-Apr-09 0:57
tom57200715-Apr-09 0:57 
GeneralRe: SQL Script Pin
kibromg15-Apr-09 1:06
kibromg15-Apr-09 1:06 
GeneralRe: SQL Script Pin
kibromg15-Apr-09 1:16
kibromg15-Apr-09 1:16 
GeneralRe: SQL Script Pin
Skymir15-Apr-09 2:35
Skymir15-Apr-09 2:35 
AnswerRe: SQL Script Pin
Dino Mulahusic15-Apr-09 1:05
professionalDino Mulahusic15-Apr-09 1:05 
GeneralRe: SQL Script Pin
kibromg15-Apr-09 1:07
kibromg15-Apr-09 1:07 
GeneralRe: SQL Script Pin
Dino Mulahusic15-Apr-09 1:09
professionalDino Mulahusic15-Apr-09 1:09 
GeneralRe: SQL Script Pin
kibromg15-Apr-09 1:13
kibromg15-Apr-09 1:13 
GeneralRe: SQL Script Pin
Ashfield15-Apr-09 1:24
Ashfield15-Apr-09 1:24 
GeneralRe: SQL Script Pin
kibromg15-Apr-09 1:57
kibromg15-Apr-09 1:57 
GeneralRe: SQL Script Pin
Ashfield15-Apr-09 9:44
Ashfield15-Apr-09 9:44 
GeneralRe: SQL Script Pin
a.hamidy15-Apr-09 1:26
a.hamidy15-Apr-09 1:26 
AnswerRe: SQL Script Pin
Christian Graus15-Apr-09 1:27
protectorChristian Graus15-Apr-09 1:27 
GeneralRe: SQL Script Pin
kibromg15-Apr-09 1:58
kibromg15-Apr-09 1:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.