public void ShouldCallbackOnCommand()
		{
			ThreadCommand.OnExecute += new OnExecuteDelegate(ThreadCommand_OnExecute);
			ThreadQueue<ThreadCommand> threadQueue = new ThreadQueue<ThreadCommand>();

			TestObject test = new TestObject();

			test.TestString = "Hello World";
			threadQueue.Enqueue(test);
			_resetEvent.WaitOne();
			threadQueue.Dispose();
		}
Пример #2
0
        public SocketComm(Socket s, bool clientSide, string socketAlias)
        {
            ShouldBeRunning = true;
            DataToSendQueue = new ThreadQueue<byte[]>();
            socket = s;
            inputThread = new Thread(new ThreadStart(inputWorker));
            outputThread = new Thread(new ThreadStart(outputWorker));
            inputProcThread = new Thread(new ThreadStart(inputProcWorker));
            if (clientSide)
            {
                inputThread.Name = "Client Socket Input Worker (" + socketAlias + ")";
                outputThread.Name = "Client Socket Input Worker (" + socketAlias + ")";
            }
            else
            {
                inputThread.Name = "Server Socket Input Worker (" + socketAlias + ")";
                outputThread.Name = "Server Socket Input Worker (" + socketAlias + ")";
            }

            inputThread.Start();
            outputThread.Start();
            inputProcThread.Start();
        }
	private void ReleaseQuery(ThreadQueue.TaskControl control, object state)
	{
        try
        {
			if( db != null )
			{
				ReleaseState rlState = state as ReleaseState;
				rlState.Query.Release();
			}
			else
			{
				throw new Exception( "Database not ready!" );
			}
        }
        catch (Exception ex)
        {
			Debug.LogError("SQLiteAsync : Exception : " + ex.Message);
        }
	}
	private void StepQuery(ThreadQueue.TaskControl control, object state)
	{
        try
        {
			if( db != null )
			{
				StepState stState = state as StepState;
				stState.Step = stState.Query.Step();
			}
			else
			{
				throw new Exception( "Database not ready!" );
			}
        }
        catch (Exception ex)
        {
			Debug.LogError("SQLiteAsync : Exception : " + ex.Message);
        }
	}
	private void CreateQuery(ThreadQueue.TaskControl control, object state)
	{
        try
        {
			if( db != null )
			{
				QueryState qrState = state as QueryState;
				qrState.Query = new SQLiteQuery(db,qrState.Sql);
			}
			else
			{
				throw new Exception( "Database not ready!" );
			}/**/
        }
        catch (Exception ex)
        {
			Debug.LogError("SQLiteAsync : CreateQuery : Exception : " + ex.Message);
        }
	}
    private void CloseDatabase(ThreadQueue.TaskControl control, object state)
    {
        try
        {
			if( db != null )
			{
            	db.Close();
				db = null;
			}
			else
			{
				throw new Exception( "Database not ready!" );
			}
        }
        catch (Exception ex)
        {
			Debug.LogError("SQLiteAsync : Exception : " + ex.Message);
        }
    }
	//
	// functions
	//
	private void OpenDatabase(ThreadQueue.TaskControl control, object state)
    {
		OpenState opState = state as OpenState;
		
        try
        {
			db = new SQLiteDB();
            db.Open(opState.Filename);
			opState.Succeed = true;
        }
        catch (Exception ex)
        {
			opState.Succeed = false;
            Debug.LogError("SQLiteAsync : OpenDatabase : Exception : " + ex.Message);
        }
    }
Пример #8
0
	void OnDestroy() 
	{
		if( thread != null )
			thread.Terminate();
		
		// clean up global value
		instance = null;
		initialized = false;
	}
Пример #9
0
        void compareFiles(int progress)
        {
            if (bitmaps == null)
                return;
            comparisions = new Dictionary<ComparableBitmap, List<ComparableBitmap>>();
            processed = new List<int>();
            double p = 0;

            for (int i = 0; i < bitmaps.Count; i++)
            {
                if (bw.CancellationPending)
                    break;

                if (!processed.Contains(i) && !comparisions.ContainsKey(bitmaps[i]))
                {

                    comparisions.Add(bitmaps[i], new List<ComparableBitmap>());
                    processed.Add(i);
                    ThreadQueue q = new ThreadQueue(bitmaps.Count / 10);
                    Levenshtein alg = new Levenshtein();

                    for (int j = 0; j < bitmaps.Count; j++)
                    {
                        if (bw.CancellationPending)
                            break;
                        q.QueueUserWorkItem((WaitCallback)delegate(object a)
                        {
                            int r = (int)a;
                            if (i != r && !processed.Contains(r))
                            {
                                int k = alg.GetDistance<byte>(bitmaps[i], bitmaps[r]);
                                if (k <= Settings.Default.SimilarityTreshold)
                                {
                                    bitmaps[r].Similarity = k;
                                    comparisions[bitmaps[i]].Add(bitmaps[r]);
                                    processed.Add(r);
                                    if (OnNewDuplicateFound != null)
                                    {

                                        OnNewDuplicateFound(this, null);
                                    }
                                }
                            }

                        }, j);
                        bw.ReportProgress((int)(++p / (double)(bitmaps.Count * bitmaps.Count) * 100), string.Format(Resources.strProceessing,
                            bitmaps[i].Path.Substring(bitmaps[i].Path.LastIndexOf('\\')+1)));

                    }
                    q.WaitAll();

                }

            }
        }
Пример #10
0
 public WindowsProcessWatcher(IActivityMonitor monitor, ThreadQueue<TickInfo> queue)
 {
     this.monitor = monitor;
     this.queue = queue;
 }
Пример #11
0
	//
	// functions
	//
	private void OpenDatabase(ThreadQueue.TaskControl control, object obj)
    {
		string filename = obj as string;
		
        try
        {
			db = new SQLiteDB();
            db.Open(filename);
			
        }
        catch (Exception ex)
        {
            Debug.LogError("SQLiteAsync : OpenDatabase : Exception : " + ex.Message);
        }
    }