Exemplo n.º 1
0
 public void Join(Expression <Action> EAMethod, int timeout = int.MaxValue)
 {
     Join(Expressions.nameofFull(EAMethod), timeout);
 }
Exemplo n.º 2
0
 public bool Terminate(Expression <Action> EAMethod)
 {
     return(Terminate(Expressions.nameofFull(EAMethod)));
 }
Exemplo n.º 3
0
 public TResult JoinF <TResult>(Expression <Func <TResult> > expression, int timeout = int.MaxValue)
 {
     return(JoinF <TResult>(Expressions.nameofFull <TResult>(expression), timeout));
 }
Exemplo n.º 4
0
 public ThreadedTimer Timer(Expression <Action> EAMethod)
 {
     return(Timer(Expressions.nameofFull(EAMethod)));
 }
Exemplo n.º 5
0
        public bool RunF <TResult>(Expression <Func <TResult> > expression, string ID, int delay, bool Exceptions, bool waitForAccess, bool invoke)
        {
            if (expression == null)
            {
                return(false);
            }


            while (MaxThreadsCount < TDSThreads.Count)
            {
                if (!waitForAccess)
                {
                    return(false);
                }
                ;

                Thread.Sleep(AccessWait);
                this.TerminateAllCompleated();
            }

            if (ID.IsNullOrEmpty())
            {
                ID = Expressions.nameofFull <TResult>(expression);
            }

            if (IsAlive(ID))
            {
                return(false);
            }

            try
            {
                if (!LockerRun.EnterWait())
                {
                    return(false);
                }

                this.Terminate(ID);

                Func <TResult> Function = expression.Compile();
                Results.Add(ID, default(TResult));

                if (Exceptions)
                {
                    if (invoke)
                    {
                        TDSThreads.Add(ID, new Thread(() => { if (delay > 0)
                                                              {
                                                                  Thread.Sleep(delay);
                                                              }
                                                              TResult result = Function.Invoke(); Results[ID] = result; }));
                    }
                    else
                    {
                        TDSThreads.Add(ID, new Thread(() => { if (delay > 0)
                                                              {
                                                                  Thread.Sleep(delay);
                                                              }
                                                              TResult result = Function(); Results[ID] = result; }));
                    }
                }
                else
                {
                    if (invoke)
                    {
                        TDSThreads.Add(ID, new Thread(() => { try { if (delay > 0)
                                                                    {
                                                                        Thread.Sleep(delay);
                                                                    }
                                                                    TResult result = Function.Invoke(); Results[ID] = result; } catch { } }));
                    }
                    else
                    {
                        TDSThreads.Add(ID, new Thread(() => { try { if (delay > 0)
                                                                    {
                                                                        Thread.Sleep(delay);
                                                                    }
                                                                    TResult result = Function(); Results[ID] = result; } catch { } }));
                    }
                }

                TDSTMFlags.Add(ID, new ThreadedMethodFlags {
                    IsAborting = false
                });

                TDSThreads[ID].Priority     = Priority;
                TDSThreads[ID].IsBackground = true;
                TDSThreads[ID].Start();
            }
            finally
            {
                LockerRun.Exit();
            }

            return(true);
        }
Exemplo n.º 6
0
        public bool Run(Expression <Action> EAMethod, string ID, int delay, bool Exceptions, bool waitForAccess, bool invoke)
        {
            if (EAMethod == null)
            {
                return(false);
            }


            while (MaxThreadsCount < TDSThreads.Count)
            {
                if (!waitForAccess)
                {
                    return(false);
                }

                Thread.Sleep(AccessWait);
                this.TerminateAllCompleated();
            }

            if (ID.IsNullOrEmpty())
            {
                ID = Expressions.nameofFull(EAMethod);
            }

            if (IsAlive(ID))
            {
                return(false);
            }

            try
            {
                if (!LockerRun.EnterWait())
                {
                    return(false);
                }

                this.Terminate(ID);

                Action Action = EAMethod.Compile();

                if (Exceptions)
                {
                    if (invoke)
                    {
                        TDSThreads.Add(ID, new Thread(() => { if (delay > 0)
                                                              {
                                                                  Thread.Sleep(delay);
                                                              }
                                                              Action.Invoke(); }));
                    }
                    else
                    {
                        TDSThreads.Add(ID, new Thread(() => { if (delay > 0)
                                                              {
                                                                  Thread.Sleep(delay);
                                                              }
                                                              Action(); }));
                    }
                }
                else
                {
                    if (invoke)
                    {
                        TDSThreads.Add(ID, new Thread(() => { try { if (delay > 0)
                                                                    {
                                                                        Thread.Sleep(delay);
                                                                    }
                                                                    Action.Invoke(); } catch { } }));
                    }
                    else
                    {
                        TDSThreads.Add(ID, new Thread(() => { try { if (delay > 0)
                                                                    {
                                                                        Thread.Sleep(delay);
                                                                    }
                                                                    Action(); } catch { } }));
                    }
                }

                TDSTMFlags.Add(ID, new ThreadedMethodFlags {
                    IsAborting = false
                });

                TDSThreads[ID].Priority     = Priority;
                TDSThreads[ID].IsBackground = true;
                TDSThreads[ID].Start();
            }
            catch (Exception e)
            {
                if (e.Message != null)
                {
                    return(false);
                }
            }
            finally
            {
                LockerRun.Exit();
            }

            return(true);
        }
Exemplo n.º 7
0
 public bool Contains(Expression <Action> EAMethod)
 {
     return(Contains(Expressions.nameofFull(EAMethod)));
 }
Exemplo n.º 8
0
 public bool IsAlive(Expression <Action> EAMethod)
 {
     return(IsAlive(Expressions.nameofFull(EAMethod)));
 }