/// <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();
        }
예제 #2
0
        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;
        }
예제 #3
0
        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);
            }
        }
예제 #4
0
 public static extern void CppLongFunction([In, Out] WorkProgressInteropNegotiator negotiator);
예제 #5
0
 public static extern int StartDiffractionSimulation([In, Out] WorkProgressInteropNegotiator negotiator, string input, string output);