简体   繁体   English

DLL中的主应用程序捕获事件

[英]main application catching event from a dll

Here is what I want to do with C# and WPF, but have limited idea how to design and implement: 这是我要使用C#和WPF进行的操作,但是对如何设计和实现的想法有限:

  • The system consists of an dll/assembly (monitor.dll) and a main application (main.exe) . 该系统由一个dll / assembly(monitor.dll)一个主应用程序(main.exe)组成

  • monitor.dll is watching a txt file that gets update when some other macro is running. monitor.dll正在监视正在运行其他宏的txt文件。 When the txt file is done updating/finish being written, the monitor.dll should release a signal that can be detected by the main.exe. 当txt文件完成更新/完成写入后,monitor.dll应释放一个可以由main.exe检测到的信号。

  • The whole process does not have to be frequent. 整个过程不必很频繁。 The monitor.dll can check the txt file every quarter second, and the frequency that the main.exe check if the monitor.dll has sent a "done" signal can be on the same order. monitor.dll可以每隔四分之一秒检查一次txt文件,并且main.exe检查monitor.dll是否已发送“完成”信号的频率可以相同。

I am wondering how should I design the system? 我想知道如何设计系统? What technique should I use? 我应该使用什么技术? Should I use BackGroundWorker int the assembly? 我应该在程序集中使用BackGroundWorker吗?

Right now I am using a timer tick in both the monotor.dll and main.exe, but it seems although the monitor.dll can catch the event, but the main.exe will always not be able to catch the signal sent by the assembly. 现在,我在monotor.dll和main.exe中都使用了计时器刻度,但似乎尽管monitor.dll可以捕获事件,但是main.exe始终无法捕获程序集发送的信号。 Thanks. 谢谢。

In the assembly, I used a timer to periodically check the .txt file status, something like this: 在程序集中,我使用计时器定期检查.txt文件的状态,如下所示:

System.Timers.Timer _logFileCheckTimer; System.Timers.Timer _logFileCheckTimer;

    public FijiLauncherControl()

    {        // timer set up
                    _logFileCheckTimer = new System.Timers.Timer(250);  
                    _logFileCheckTimer.Enabled = true;
                    _logFileCheckTimer.Elapsed += new System.Timers.ElapsedEventHandler(_logFileCheckTimer_Elapsed);
                   _logFileCheckTimer.Start();  // start the timer

     }    

     void _logFileCheckTimer_Elapsed(object sender, EventArgs e)
        {
            if (_processOn && IsLogOn)
            {
                try
                {
                    _processFinished = CheckStatuts();  // checking file status

                    if (_processFinished) // fire event if checking status returns true
                    {
                        OnIjmFinished(EventArgs.Empty);
                        _processOn = false;
                        _logFileCheckTimer.Stop();
                    }
                }
                catch (Exception ex)
                {

                }
            }
        }

In the aseembly. 在外观上。 setup a event in the dll that will be triggered if the _processFinished = CheckStatuts(); 在dll中设置一个事件,如果_processFinished = CheckStatuts();则会触发该_processFinished = CheckStatuts(); returns true : 返回true

// event delegate public delegate void IjmFinishedEventHandler(object sender, EventArgs e); //事件委托公共委托void IjmFinishedEventHandler(object sender,EventArgs e); public event IjmFinishedEventHandler IjmFinished; 公共事件IjmFinishedEventHandler IjmFinished; // event handler //事件处理程序

   protected virtual void OnIjmFinished(EventArgs e)
   {
      if (IjmFinished != null)   // trigger event
                IjmFinished(this, e);          
   }

In the main application, there should be event receiver, something like this: 在主应用程序中,应该有事件接收器,如下所示:

private FijiLauncherControl _fl; // the object of your assembly

  _fl.IjmFinished += new IjmFinishedEventHandler(_fl_IjmFinished); // event from the assembly should trigger an event handler

   void _fl_IjmFinished(object sender, EventArgs e)   // event handler
        {
            _vm.IjmFinished = true;   // a boolean var in viewmodel in main app set to be true once the event from the assembly is triggered

            //throw new NotImplementedException();
        }

That should do the job. 那应该做的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从 codedom 生成的 dll 触发事件 - 如何加入运行时生成的 dll 表单主 exe 应用程序的事件 - event firing from codedom generated dll - how to join an event of a runtime generated dll form main exe application 从另一个DLL(或应用程序)触发DLL事件 - Fire DLL event from another DLL (or Application) 从另一个应用程序订阅dll中的事件 - Subscribe to event in dll from another application 如何将异常消息从DLL传递到主应用程序 - How to pass exception message from DLL to main application 在其他应用程序中捕获按钮单击事件 - Catching the button click event in other application 在dll而不是主应用程序中查找资源 - Finding resource in dll instead of main application 想要将动态文件路径从主Web应用程序传递到单独的DLL。 该DLL是使用NLog单独完成的 - Want to pass dynamic File path from main web application to a separate DLL. That DLL is separately done using NLog C#没有捕获非托管C ++ DLL的未处理异常 - C# not catching unhandled exceptions from unmanaged C++ dll 捕获DLL崩溃 - Catching a DLL Crash 如果我从加载的 dll 文件而不是主应用程序访问 static 值,为什么它的值会不同? - Why is a static value different if I access it from a loaded dll file instead of the main application?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM