09-08-2020 07:46 AM
1. This example is special in C# DLL
normally, we use system predefined delegate "Eventhandler" to define a event with no user params, So, we just use all the base class to define callback method
(object sender, EventArgs e) as input params. And Sender meas some UI control trigged action, Such as key/mouse interface etc.,, e is system defined params, such as click, down etc.,
Here, We just raise the event by our application , Not the windows OS hardware actions. And we tied some param within 'Sender' for callback functions....one is percent(int32, 0~100),another is result(bool,true/false) which means the state of dll during receive a file
2.In labview, how callback function get user information which tied within C# DLL's "sender"?
3.labview2020(32bit),visual studio2019 used(64bit).
Solved! Go to Solution.
09-08-2020 09:06 AM
09-09-2020 09:41 AM
09-09-2020 10:18 AM - edited 09-09-2020 10:22 AM
OK, sorry about the noise. It was only slightly related...
There seems to be nothing wrong with the LabVIEW code. Not sure about the C# code.
Can't run your code, as I don't have a local webserver... Never mind. The C# code is just a stub...
Are the callbacks triggered (put a message box in them, or make them not reentrant and use a probe)? Can you put error handler dialogs in there? Perhaps the Variant To Data fails...
Are you sure the assembly is generating events?
09-09-2020 10:31 AM - edited 09-09-2020 10:32 AM
Where did you get the C# code from? Is it based on an example?
I'm no C# expert, and I suspect no events are generated at all Intuitively, it seems to me the EventHandlers need to be created (not just defined) and somewhere an AddEventHandler should be used. But this might be completelly wrong.
I'd try to make a C# exe that calls the assembly, to and get that working first. Until it works in C#, LabVIEW has no change...
09-10-2020 10:22 AM
09-10-2020 10:31 AM
@guohuimao wrote:
The hard part is how we can convert the 'sender' form C# object to labview var, the to int or bool in labview.
The callbacks are not called at all.
The conversion happens in the callback. But if they are not called, I think that is the first thing to solve?
09-10-2020 10:45 AM
09-10-2020 10:52 AM
09-10-2020 10:54 AM
@guohuimao wrote:
I did not know how to debug the event in labview, I think callback is called by CLR, maybe difficult to catch it to see some action. As i study early about callback in labview, I know callback function has some error sure.
If you make the callbacks non-reentrant, they work like normal VIs. You can put probes in it. But they won't get values, as the callback isn't triggered.
You can practice with callback VIs. Simply wire a LabVIEW control reference in stead of the .NET reference. You'll get the usual LV events you normally get in an event structure.
You can also put a popup (One Button Dialog) in the callback. If it doesn't show, the callback isn't called.
If you have working C# code to test the event, can you post it?
@guohuimao wrote:
So we try to pick out where is the problem ..
I'd be interested in this as well. I've used .NET events before, but never had to create the .NET code.
The link I posted in the first reply is an example of an event. It should be that simple, from the LabVIEW side. But I have no idea how to make in in C# and I haven't found any examples either.