adhere


Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[C#]Multithread class
Author Message
BaussHacker Offline
Silver Member
**

Posts: 138
Joined: Aug 2011
Reputation: 0
Given 0 thank(s) in 0 post(s)
Post: #1
Thread [C#]Multithread class
Not tested, but it seems to work.

Just did it now, was a bit bored.

PHP Code:
public enum ThreadStatus
    
{
        
SuccessRunning,
        
FailedToInvoke,
        
FailedToAbort,
        
Closed
    
}
    public class 
ThreadQuery
    
{
        public 
ThreadQuery(int Interval)
        {
            
m_interval Interval;
        }
        private 
int m_interval;
        private 
System.Threading.Thread m_thread;
        public 
event Action Event;

        public 
void Start()
        {
            
m_thread = new System.Threading.Thread(new System.Threading.ThreadStart(Run));
            
m_thread.Start();
            
CurrentStatus ThreadStatus.SuccessRunning;
        }
        public 
ThreadStatus CurrentStatus ThreadStatus.Closed;
        private 
bool Closed false;
        private 
void Run()
        {
            while (!
Closed)
            {
                if (
DateTime.Now >= DateTime.Now.AddMilliseconds(m_interval))
                {
                    try
                    {
                        
Event.Invoke();
                        
CurrentStatus ThreadStatus.SuccessRunning;
                    }
                    catch { 
CurrentStatus ThreadStatus.FailedToInvoke; }

                }
                
Thread.Sleep(1);
            }
            
CurrentStatus ThreadStatus.Closed;
        }
        public 
void Abort()
        {
            try
            {
                
m_thread.Join();
                
m_thread.Abort();
                
CurrentStatus ThreadStatus.Closed;
            }
            catch
            {
                
CurrentStatus ThreadStatus.FailedToAbort;
            }

            
Closed true;
        }
    } 
08-21-2011 09:08 AM
Find all posts by this user Quote this message in a reply
Advertisement
envyus
Gera Offline
Newbie

Posts: 7
Joined: Jul 2012
Reputation: 0
Given 0 thank(s) in 0 post(s)
Post: #2
Thread RE: [C#]Multithread class
Once i tried using multithreading in windows application.I used AutoResetEvent and WaitForAll..I was getting this error..You can not use MTA in STA.I mean..is it not possible or is there a proper way 2 do so..??
07-24-2012 01:03 PM
Find all posts by this user Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 1 Guest(s)
Navigation
adhere
Sponsors
afil
Alexa Rank