Ejemplo n.º 1
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait;
            RichText.Document.Blocks.Add(new Paragraph(new Run("Waiting For Searching...")));
            WorkerClass wc = new WorkerClass();

            //ContentData cd = new ContentData();

            //RichText.Text = wc.getSourceCode("www.google.com");
            //.RichText.RichText.t = wc.getSourceCode("www.google.com");
            //RichText.Document.Blocks.Clear();
            //RichText.Document.Blocks.Add(new Paragraph(new Run(wc.getSourceCode("http://www.bongda.com.vn"))));

            if (EnterBox.Text != "")
            {
                Dictionary <string, string> contentList = new Dictionary <string, string>();
                // RichText.Document.Blocks.Clear();
                contentList["address"] = EnterBox.Text;
                RichText.Document.Blocks.Clear();
                //string content = wc.getContentOnly(str + EnterBox.Text);
                //string content = wc.getAllConnectingUrl2(str + EnterBox.Text);
                wc.Question      = EnterBox.Text;
                summarizeContent = wc.analysisTheContentDiv(str + EnterBox.Text);
                // EnterBox.Text = "It might take a few minutes. Please Wait....";
                // string content = cd.CollectDataPerLink("http://www.encyclopedia.com/topic/Bill_Gates.aspx");
                string    content = ConvertContentToString(summarizeContent);
                Paragraph p       = new Paragraph(new Run(content));
                RichText.Document.Blocks.Add(p);
                //EnterBox.Text = "Ready for new question";
            }
            Mouse.OverrideCursor = null;
        }
Ejemplo n.º 2
0
 static Variables()
 {
     m_wClass = new WorkerClass();
     // creates and registers an event timer
     m_flushTimer          = new System.Timers.Timer(1000);
     m_flushTimer.Elapsed += new System.Timers.ElapsedEventHandler(OnFlushTimer);
     m_flushTimer.Start();
 }
Ejemplo n.º 3
0
 public InicioView(HTuple window)
 {
     InitializeComponent();
     configAcquisitionDevice = ConfigAcquisitionDevice.Instance;
     workerClass             = new WorkerClass();
     this.window             = window;
     configAcquisitionDevice.IsConfiguredEvent += ConfigAcquisitionDevice_IsConfiguredEvent;
 }
Ejemplo n.º 4
0
 public void CommandCallBack(IAsyncResult ar)
 {
     // this is called when your task is complete
     AsyncResult asyncResult = (AsyncResult)ar;
     MyDelegate  myDel       = (MyDelegate)asyncResult.AsyncDelegate;
     WorkerClass command     = myDel.EndInvoke(ar);
     // command is a reference to the original class that envoked the async call
     // m_test will equal "Hi"
     // m_test2 will equal "Later";
 }
Ejemplo n.º 5
0
    static void Main(string[] args)
    {
        WorkerClass worker = new WorkerClass();

        worker.Callback = new WorkerCallbackDelegate(WorkerCallback);
        System.Threading.Thread thread = new System.Threading.Thread(worker.DoWork);
        thread.Start();
        while (!done)
        {
            System.Threading.Thread.Sleep(100);
        }
        Console.WriteLine("Done");
        Console.ReadLine();
    }
Ejemplo n.º 6
0
        public static int StartWorker(WorkerDelegate onWork, WorkerFinishedDelegate onFinish = null, WorkerOnProgressDelegate onUpdate = null)
        {
            for (int i = 0; i < m_workerList.Count; i++)
            {
                if (!m_workerList[i].worker.IsBusy)
                {
                    m_workerList[i].onWork     = onWork;
                    m_workerList[i].onProgress = onUpdate;
                    m_workerList[i].onFinish   = onFinish;
                    m_workerList[i].worker.RunWorkerAsync();
                    return(i);
                }
            }
            WorkerClass worker = new WorkerClass();

            worker.onWork     = onWork;
            worker.onProgress = onUpdate;
            worker.onFinish   = onFinish;
            m_workerList.Add(worker);
            worker.worker.RunWorkerAsync();
            return(m_workerList.Count - 1);
        }
Ejemplo n.º 7
0
        public virtual void Listen()
        {
            WorkerCollection lWorkers = null;

            if (Owner.CloseConnectionsOnShutdown)
            {
                lWorkers = new WorkerCollection();
            }

            try
            {
                Socket lSocket;
                do
                {
                    try
                    {
                        lSocket = fListeningSocket.Accept();
                    }
                    catch (ObjectDisposedException)
                    {
                        return;
                    }
                    catch (SocketException)
                    {
                        /* If Accept fails with a SocketException, the socket was ListeningSocket was probably
                         * closed, so we'll just exit and terminate the thread. */
                        return;
                    }

                    if (lSocket != null)
                    {
                                                #if echoes
                        Object lObject = Activator.CreateInstance(WorkerClass);
                                                #elif cooper
                        Object lObject = Class.getDeclaredConstructor(WorkerClass).newInstance();
                                                #elif island
                        Object lObject = WorkerClass.Instantiate();
                                                #elif toffee
                        Object lObject = WorkerClass.init();
                                                #endif
                        IWorker lWorker = lObject as IWorker;
                        lWorker.Owner = Owner;

                        if (Owner.ConnectionFactory != null)
                        {
                            lWorker.DataConnection = Owner.ConnectionFactory.CreateServerConnection(lSocket);
                        }
                                                #if ECHOES
                        else if (Owner.ConnectionClass != null)
                        {
                            lWorker.DataConnection = (Connection)Activator.CreateInstance(Owner.ConnectionClass);
                            lWorker.DataConnection.Init(lSocket);
                        }
                                                #endif
                                                #if FULLFRAMEWORK
                        else if (Owner.SslOptions.Enabled)
                        {
                            lWorker.DataConnection = Owner.SslOptions.CreateServerConnection(lSocket);
                        }
                                                #endif
                        else
                        {
                            lWorker.DataConnection = new Connection(lSocket);
                        }

                                                #if FULLFRAMEWORK
                        if (Owner.TimeoutEnabled)
                        {
                            lWorker.DataConnection.TimeoutEnabled = true;
                            lWorker.DataConnection.Timeout        = Owner.Timeout;
                        }
                                                #endif

                        if (Owner.MaxLineLengthEnabled)
                        {
                            lWorker.DataConnection.MaxLineLengthEnabled = true;
                            lWorker.DataConnection.MaxLineLength        = Owner.MaxLineLength;
                        }

                        try
                        {
                            lWorker.DataConnection.InitializeServerConnection();
                        }
                        catch (Exception)                         // nothing should escape this loop.
                        {
                            lWorker.DataConnection.Dispose();
                            continue;
                        }

                        lWorker.Thread = new Thread(() => { lWorker.Work(); });
                        try
                        {
                                                        #if FULLFRAMEWORK
                            lWorker.Thread.Name = String.Format("Internet Pack {0} for {1}", WorkerClass.Name, lSocket.RemoteEndPoint);
                                                        #endif
                        }
                        catch (SocketException)
                        {
                            // mono can fail in that code if the remote side has been disconnected. Since we already create a thread we have to run it (leak otherwise)
                        }

                        if (lWorkers != null)
                        {
                            lWorkers.Add(lWorker);
                        }

                        lWorker.Thread.Start();
                    }
                }while (lSocket != null);
            }
            finally
            {
                if (lWorkers != null)
                {
                    lWorkers.Close();
                }
            }
        }
Ejemplo n.º 8
0
 public static void Initialize(WorkerClass newHumanClass)
 {
     humanClasses.Add(newHumanClass);
 }
Ejemplo n.º 9
0
        static void Main(string[] args)
        {
            int  numThreads;
            bool processingComplete = false;

            startTime = DateTime.Now;

            if (args.Length == 0)
            {
                numIterations = 1000;
                numThreads    = 1;
            }
            else
            {
                numIterations = Convert.ToInt32(args[0]);

                if (args.Length == 1)
                {
                    numThreads = 1;
                }
                else
                {
                    numThreads = Convert.ToInt32(args[1]);
                }
            }

            for (int i = 0; i < numThreads; i++)
            {
                WorkerClass wc = new WorkerClass();

                Thread t = new Thread(new ThreadStart(wc.SendEvents));
                t.Name = i.ToString();
                workerThreads.Add(t);
            }

            for (int i = 0; i < numThreads; i++)
            {
                workerThreads[i].Start();
            }

            while (processingComplete == false)
            {
                Thread.Sleep(1000);

                processingComplete = true;

                for (int i = 0; i < numThreads; i++)
                {
                    if (workerThreads[i].IsAlive == true)
                    {
                        processingComplete = false;
                    }
                }
            }

            DateTime stopTime  = DateTime.Now;
            TimeSpan totalTime = new TimeSpan(stopTime.Ticks - startTime.Ticks);

            Console.WriteLine(" ");

            Console.WriteLine("Overall time was: " + totalTime.TotalSeconds.ToString() + " seconds");
            Console.WriteLine(((numIterations * numThreads) / totalTime.TotalSeconds).ToString() + " events per second");
        }