예제 #1
0
 public static void Initialize(Form form)
 {
     if (_instance == null)
     {
         _instance = new MainThread(form);
     }
 }
예제 #2
0
        public static void DispatchEvent(string eventName, params object[] eventData)
        {
            Dictionary <object, MethodInfo> tableEvent = null;
            Dictionary <object, MethodInfo> tableAll   = null;

            bool handlerNotFound = true;;

            lock (_invocationMap)
            {
                if (_invocationMap.ContainsKey(eventName))
                {
                    //try
                    //{
                    tableEvent = SafeCopy(_invocationMap[eventName]);
                    tableAll   = SafeCopy(_invocationMap[AllEvents]);
                    //}
                    //catch (Exception ex)
                    //{
                    //}

                    handlerNotFound = false;
                }
            }

            if (tableEvent != null)
            {
                foreach (KeyValuePair <object, MethodInfo> kvp in tableEvent)
                {
                    try
                    {
                        MainThread.Post(delegate(object x)
                        {
                            kvp.Value.Invoke(kvp.Key, eventData);
                        });
                    }
                    catch (TargetInvocationException ex)
                    {
                        Logger.LogException(ex.InnerException);
                    }
                    catch (Exception ex)
                    {
                        Logger.LogException(ex);
                    }
                }
            }

            if (tableAll != null)
            {
                foreach (KeyValuePair <object, MethodInfo> kvp in tableAll)
                {
                    try
                    {
                        kvp.Value.Invoke(kvp.Key, eventData);
                    }
                    catch (TargetInvocationException ex)
                    {
                        Logger.LogException(ex.InnerException);
                    }
                    catch (Exception ex)
                    {
                        Logger.LogException(ex);
                    }
                }
            }

            if (handlerNotFound)
            {
                if (eventName == EventNames.ShowMessageBox)
                {
                    ProcessMessageBoxEvent(eventData);
                }
            }
        }