Hi,
I wrote a C# program that is calling C++ legacy code to open a serial port
(using CreateFile (comPort,
GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_EXISTING,FILE_FLAG_OVERLAPPED,NULL))
.
So far, it works.
Now, at startup, I start 4 C# threads.
These threads are opening Com ports #2, #3, #4 and #5.
Sometimes, these 4 Com ports are opened successfully but, most of the time,
1 Com port opening failed.
The GetLastError returns 5 (access denied).
So, my question is :
Is it safe to call 4 CreateFile (for different Com ports of course) in
parallel thread at the same time ?
Thanks in advance for your help,
Droopy.
Droopy - 11 Jul 2005 15:53 GMT
> Hi,
>
[quoted text clipped - 17 lines]
>
> Droopy.
Who can help me ?
Willy Denoyette [MVP] - 15 Jul 2005 17:57 GMT
Yes it is. The "Access denied" error code has IMO nothing to do with the
number of threads, are you sure this error is returned by the CreateFile
call?
Willy.
> Hi,
>
[quoted text clipped - 18 lines]
>
> Droopy.
Droopy - 19 Jul 2005 14:42 GMT
Yes.
To be more precise, CreateFile returns INVALID_HANDLE_VALUE and
GetLastError () returns 5 (Access Denied)
Sorry for this late answer.
> Yes it is. The "Access denied" error code has IMO nothing to do with
> the number of threads, are you sure this error is returned by the
[quoted text clipped - 24 lines]
>>
>> Droopy.
Droopy - 25 Jul 2005 14:37 GMT
Who can help me ?
Have I to start it sequentially or add any timeout between thread
starting ?
> Yes.
> To be more precise, CreateFile returns INVALID_HANDLE_VALUE and
[quoted text clipped - 12 lines]
>>> I wrote a C# program that is calling C++ legacy code to open a serial
>>> port (using CreateFile (comPort,
GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_EXISTING,FILE_FLAG_OVERLAPPED,N
>>> ULL)) .
>>> So far, it works.
[quoted text clipped - 13 lines]
>>>
>>> Droopy.