ja patrząc na wielu wątków o wyjątku „nie może przejść GCHandle całej AppDomains”, ale ja nadal nie rozumiem ....GCHandle, AppDomains kodu zarządzanego i 3rd party dll
pracuję z czytnik RFID obsługiwany przez bibliotekę DLL. Nie mam kodu źródłowego dla tej biblioteki DLL, ale tylko próbkę, aby pokazać, jak z niego korzystać.
Próbka działa świetnie, ale muszę skopiować kod w innym projekcie, aby dodać czytnik do oprogramowania pośredniego Microsoft Biztalk.
Problem polega na tym, że proces Microsoft Biztalk działa w innym AppDomain. Czytnik obsługuje zdarzenia po odczytaniu znacznika. Ale kiedy uruchomiłem go pod Microsoft Biztalk, dostałem ten denerwujący wyjątek.
Nie widzę żadnego rozwiązania, w jaki sposób, aby to działało ...
Oto kod, który może być interesujący:
// Let's connecting the result handlers.
// The reader calls a command-specific result handler if a command is done and the answer is ready to send.
// So let's tell the reader which functions should be called if a result is ready to send.
// result handler for reading EPCs synchronous
Reader.KSRWSetResultHandlerSyncGetEPCs(ResultHandlerSyncGetEPCs);
[...]
var readerErrorCode = Reader.KSRWSyncGetEPCs();
if (readerErrorCode == tKSRWReaderErrorCode.KSRW_REC_NoError)
{
// No error occurs while sending the command to the reader. Let's wait until the result handler was called.
if (ResultHandlerEvent.WaitOne(TimeSpan.FromSeconds(10)))
{
// The reader's work is done and the result handler was called. Let's check the result flag to make sure everything is ok.
if (_readerResultFlag == tKSRWResultFlag.KSRW_RF_NoError)
{
// The command was successfully processed by the reader.
// We'll display the result in the result handler.
}
else
{
// The command can't be proccessed by the reader. To know why check the result flag.
logger.error("Command \"KSRWSyncGetEPCs\" returns with error {0}", _readerResultFlag);
}
}
else
{
// We're getting no answer from the reader within 10 seconds.
logger.error("Command \"KSRWSyncGetEPCs\" timed out");
}
}
[...]
private static void ResultHandlerSyncGetEPCs(object sender, tKSRWResultFlag resultFlag, tKSRWExtendedResultFlag extendedResultFlag, tKSRWEPCListEntry[] epcList)
{
if (Reader == sender)
{
// Let's store the result flag in a global variable to get access from everywhere.
_readerResultFlag = resultFlag;
// Display all available epcs in the antenna field.
Console.ForegroundColor = ConsoleColor.White;
foreach (var resultListEntry in epcList)
{
handleTagEvent(resultListEntry);
}
// Let's set the event so that the calling process knows the command was processed by reader and the result is ready to get processed.
ResultHandlerEvent.Set();
}
}
Najpierw dziękuję za odpowiedź.Właściwie udało mi się wprowadzić obiekt z biblioteki DLL i użyć go. Jak widać w powyższym kodzie, podłączam metodę (ResultHandlerSyncGetEPCs) do zdarzenia wysyłanego przez czytnik, gdy czyta znaczniki. Awaria kodu źródłowego w linii czekającej na zdarzenie ... Nie czeka na co najmniej 10 sekund na przekroczenie limitu czasu, natychmiast rzuca "nie można przekazać GCHandle ..." wyjątku. – hurtauda
I widzę, że czytnik jest dobrze podłączony i może odbierać metodę "Reader.KSRWSyncGetEPCs();" , ponieważ czyta znaczniki na antenie w tym momencie. – hurtauda
Podałem konkretną rekomendację, aby zdiagnozować źródło problemu. Jeśli nie chcesz tego robić, skontaktuj się bezpośrednio ze sprzedawcą w celu uzyskania wsparcia. –