public ThreadP2Ctrl_Message(long xMessage_ID, eMessage xMessage, ThreadP_Message.delegate_Procedure xporocedure, object oResult, string ErrorMessage)
 {
     Message_ID = xMessage_ID;
     m_Message = xMessage;
     m_Procedure = xporocedure;
     m_oResult = oResult;
     m_ErrorMessage = ErrorMessage;
 }
Exemple #2
0
        private void Run(object othdata)
        {
            ThreadData thdata = (ThreadData)othdata;
            ThreadP2Ctrl_MessageBox xThreadP2Ctrl_MessageBox = thdata.m_ThreadP2Ctrl_MessageBox;
            ThreadP_Message p_message = new ThreadP_Message(0, ThreadP_Message.eMessage.NONE, null,null);
            ThreadP2Ctrl_Message xThreadP2Ctrl_Message = new ThreadP2Ctrl_Message(0, ThreadP2Ctrl_Message.eMessage.START, null,null,null);
            xThreadP2Ctrl_MessageBox.Post(xThreadP2Ctrl_Message);
            for (;;)
            {
                switch (message_box.Get(ref p_message))
                {
                    case Result_MessageBox_Get.OK:
                        switch (p_message.Message)
                        {

                            case ThreadP_Message.eMessage.TASK:
                                ThreadP_Message.delegate_Procedure proc = p_message.Procedure;
                                object oParam = p_message.ParameterAsObject;
                                string Err = null;
                                object oResult = proc(oParam, ref Err);
                                if (oResult is bool)
                                {
                                    if (!(bool)oResult)
                                    {
                                        xThreadP2Ctrl_Message.Set(0, ThreadP2Ctrl_Message.eMessage.ERROR, proc, oResult, Err);
                                    }
                                    else
                                    {
                                        xThreadP2Ctrl_Message.Set(0, ThreadP2Ctrl_Message.eMessage.MESSAGE, proc, oResult, Err);
                                    }
                                }
                                else
                                {
                                    xThreadP2Ctrl_Message.Set(0, ThreadP2Ctrl_Message.eMessage.MESSAGE, proc, oResult, Err);
                                }

                                xThreadP2Ctrl_MessageBox.Post(xThreadP2Ctrl_Message);
                                break;

                            case ThreadP_Message.eMessage.END:
                                xThreadP2Ctrl_Message.Set(0, ThreadP2Ctrl_Message.eMessage.END, null,null,null);
                                xThreadP2Ctrl_MessageBox.Post(xThreadP2Ctrl_Message);
                                return;
                        }
                        break;
                    case Result_MessageBox_Get.TIMEOUT:
                        break;
                }
            }
        }
 public CircularBuffer_ThreadP_Message(int xLength)
 {
     if (xLength > 0)
     {
         m_Length = xLength;
         m_obuff = new ThreadP_Message[m_Length] ;
         for (int i=0;i< m_Length;i++)
         {
             ThreadP_Message mfvi = new ThreadP_Message(0, ThreadP_Message.eMessage.NONE,null,null);
             m_obuff[i] = mfvi;
         }
     }
     pIn = 0;
     pOut = 0;
 }
Exemple #4
0
 public bool Start(int message_box_length, ThreadP_Message.delegate_Procedure proc, object xparam, int timeOutInSec, ref string ErrReason)
 {
     try
     {
         m_ThreadP2Ctrl_MessageBox = new ThreadP2Ctrl_MessageBox(message_box_length);
         ThreadData thdata = new ThreadData(proc, xparam, timeOutInSec, m_ThreadP2Ctrl_MessageBox);
         message_box = new ThreadP_MessageBox(message_box_length);
         FVI_Thread = new System.Threading.Thread(Run);
         FVI_Thread.SetApartmentState(ApartmentState.STA);
         FVI_Thread.Start(thdata);
         return true;
     }
     catch (Exception ex)
     {
         ErrReason = ex.Message;
         return false;
     }
 }
 public bool Get(ref ThreadP_Message msg)
 {
     if (pOut != pIn)
     {
         msg.Message = m_obuff[pOut].Message;
         msg.Procedure = m_obuff[pOut].Procedure;
         msg.ParameterAsObject = m_obuff[pOut].ParameterAsObject;
         msg.Message_ID = m_obuff[pOut].Message_ID;
         m_obuff[pOut].Message = ThreadP_Message.eMessage.NONE;
         m_obuff[pOut].Procedure = null;
         m_obuff[pOut].ParameterAsObject = null;
         pOut = Next(pOut);
         return true;
     }
     else
     {
         return false;
     }
 }
 public Result_MessageBox_Post Post(ThreadP_Message Message)
 {
     Result_MessageBox_Post res = Result_MessageBox_Post.TIMEOUT;
     if (myMutex.WaitOne(3000))
     {
         if (message_buff.PutIn(Message))
         {
             res = Result_MessageBox_Post.OK;
         }
         else
         {
             res = Result_MessageBox_Post.FULL;
         }
         myMutex.ReleaseMutex();
     }
     else
     {
         res = Result_MessageBox_Post.TIMEOUT;
     }
     return res;
 }
Exemple #7
0
        public bool End()
        {
            ThreadP2Ctrl_Message xThreadP2Ctrl_Message_END = new ThreadP2Ctrl_Message(0, ThreadP2Ctrl_Message.eMessage.NONE, null,null,null);
            ThreadP_Message ThreadP_message_END = new ThreadP_Message(0, ThreadP_Message.eMessage.END, null,null);
            message_box.Post(ThreadP_message_END);
            long StartTicks = DateTime.Now.Ticks;

            for (;;)
            {
                if (m_ThreadP2Ctrl_MessageBox.Get(ref xThreadP2Ctrl_Message_END) == Result_MessageBox_Get.OK)
                {
                    if (xThreadP2Ctrl_Message_END.Message == ThreadP2Ctrl_Message.eMessage.END)
                    {
                        return true;
                    }
                }
                if ((DateTime.Now.Ticks - StartTicks) > 100000000)
                {
                    return false;
                }
            }
        }
 public Result_MessageBox_Get Get(ref ThreadP_Message Message)
 {
     Result_MessageBox_Get res = Result_MessageBox_Get.TIMEOUT;
     if (myMutex.WaitOne(3000))
     {
         if (message_buff.Get(ref Message))
         {
             res = Result_MessageBox_Get.OK;
         }
         else
         {
             res = Result_MessageBox_Get.EMPTY;
         }
         myMutex.ReleaseMutex();
     }
     else
     {
         //Timeout !
         res = Result_MessageBox_Get.TIMEOUT;
     }
     return res;
 }
 public Upgrade(string DBVer, ThreadP_Message.delegate_Procedure proc)
 {
     DBVersion = DBVer;
     procedure = proc;
 }
 public bool PutIn(ThreadP_Message msg)
 {
     int pInNext = Next(pIn);
     if (pInNext == pOut)
     {
         return false;
     }
     else
     {
         m_obuff[pIn].Message = msg.Message;
         m_obuff[pIn].Procedure = msg.Procedure;
         m_obuff[pIn].ParameterAsObject = msg.ParameterAsObject;
         m_obuff[pIn].Message_ID = msg.Message_ID;
         pIn = pInNext;
         return true;
     }
 }
Exemple #11
0
 public ThreadData(ThreadP_Message.delegate_Procedure procedure,object xParameterAsObject, int xtimeOutInSec, ThreadP2Ctrl_MessageBox x_ThreadP2Ctrl_MessageBox)
 {
     Procedure = procedure;
     ParameterAsObject = xParameterAsObject;
     timeOutInSec = xtimeOutInSec;
     m_ThreadP2Ctrl_MessageBox = x_ThreadP2Ctrl_MessageBox;
 }
Exemple #12
0
 public void Execute(RPCd rpcd)
 {
     ThreadP_Message msg = new ThreadP_Message(msg_ID, ThreadP_Message.eMessage.TASK, SendUser_WaitResponse, rpcd);
     threadp.message_box.Post(msg);
 }