/// <summary> /// Method for ThreadStart delegate /// </summary> public void RunProcess() { Thread.CurrentThread.IsBackground = true; //make them a daemon WorkProgressInteropNegotiator negotiator = new WorkProgressInteropNegotiator(); negotiator.reportProgress = new ReportProgressCallback(ReportProgress); negotiator.cancellationPending = new CancellationPendingCallback(() => { return(Stop); }); // Refer for details to // "How to: Marshal Callbacks and Delegates Using C++ Interop" // http://msdn.microsoft.com/en-us/library/367eeye0%28v=vs.100%29.aspx GCHandle gch = GCHandle.Alloc(negotiator); CppLongFunction(negotiator); gch.Free(); }
static void CSharpLongFunctionWrapper(object sender, DoWorkEventArgs e) { BackgroundWorker bw = sender as BackgroundWorker; WorkProgressInteropNegotiator negotiator = new WorkProgressInteropNegotiator(); negotiator.reportProgress = new ReportProgressCallback(bw.ReportProgress); negotiator.cancellationPending = new CancellationPendingCallback(() => bw.CancellationPending); // Refer for details to // "How to: Marshal Callbacks and Delegates Using C++ Interop" // http://msdn.microsoft.com/en-us/library/367eeye0%28v=vs.100%29.aspx GCHandle gch = GCHandle.Alloc(negotiator); CppLongFunction(negotiator); gch.Free(); e.Cancel = negotiator.cancel; }
void bgWorker_DoWork(object sender, DoWorkEventArgs e) { WorkProgressInteropNegotiator negotiator = new WorkProgressInteropNegotiator(); negotiator.reportProgress = new ReportProgressCallback(ReportProgress); negotiator.cancellationPending = new CancellationPendingCallback(() => { return(Stop); }); try { StartDiffractionSimulation(negotiator, Input, Output); } catch (Exception ex) { System.Console.WriteLine("Problem with loading dll"); System.Console.WriteLine(ex.Message); } }
public static extern void CppLongFunction([In, Out] WorkProgressInteropNegotiator negotiator);
public static extern int StartDiffractionSimulation([In, Out] WorkProgressInteropNegotiator negotiator, string input, string output);