LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

asynchronuous functions don't work in a C# dll used by a CVI application

Solved!
Go to solution

Hello,

 

I have an existing application written with CVI 9.0.1, which have to interact with a C# 2010 dll (which doesn't have any window) via a CVI<->.net wrapper (created using the usefull .net controller of CVI).

This C# dll uses asynchronuous functions, like NetworkStream.BeginRead() and EndRead() functions of a System.Net.Sockets.TcpClient object for example.

 

These asynchronuous functions work fine when the C# dll is used by a C# application (having a main window) or when the C# dll is converted in a standalone C# program (having a main window with buttons, to call its methods, just to try), but asynchronuous functions don't work when my C# dll is called by my CVI application (which is my goal): execution stays inside NetworkStream.BeginRead() for example (for the concerned thread).

 

NetworkStream.BeginRead() can be successfully bypassed by using the synchronuous function NetworkStream.Read() instead, but the C# dll uses others asynchronuous functions wich have no associated synchronuous functions.

 

Here is a portion of C# code (I don't have the source code for the Snmp object ; got_trap() method is never called when asynchonuous calls don't work):

 

public void run() // the thread

{

 Snmp snmp = null;

 try

  {

  snmp = new Snmp(true);

  snmp.NotifyListenPort = 162;

  snmp.NotifyRegister(null, null, new NotifyCallback(got_trap), CB_DATA_);

  isActive = true;

  Thread.Sleep(Timeout.Infinite);

 }

 ...

}

 

Thinking it could be a problem with window messages which could be not processed (in the C# dll), I tried to replace the Thread.Sleep(Timeout.Infinite) instruction, in the code where the asynchronuous management take place, by a window creation plus my Win32 window message loop, but asynchronuous functions don't work better (whereas my loop seems to successfully process messages):

 

Form myForm = new Form(); // an empty window

myForm.Show();

int bRet;

MSG msg = new MSG();

while ((bRet = GetMessage(out msg, IntPtr.Zero, 0, 0)) != 0)

{

    if (bRet == -1)

    {

       // handle the error and possibly exit

    }

    else

    {

      switch (msg.message)

      {

        default: // everything else

        TranslateMessage(ref msg);

        DispatchMessage(ref msg);

        break;

      }

    }

  }

 

Any idea ?

Thank you,

rvfr.

0 Kudos
Message 1 of 2
(2,771 Views)
Solution
Accepted by topic author rvfr

Solved: in fact, the snmp assembly that I was using just needed to be dotNet registered.

 

rvfr.

0 Kudos
Message 2 of 2
(2,691 Views)