コード例 #1
0
        public string Run()
        {
            Task nodeTask = new Task(() =>
            {
                MainServiceReference.MainServiceSoapClient client = new MainServiceReference.MainServiceSoapClient();
                MainServiceReference.WorkItem item;

                StockQuery worker = new StockQuery();

                while ((item = client.GetWork()) != null)
                {
                    try
                    {
                        using (stockdbaEntities db = new stockdbaEntities())
                        {
                            db.ServiceLog.Add(new ServiceLog() { updateTime = DateTime.Now, updateLog = string.Format("Run:{0}", item.stockId) });
                            db.SaveChanges();
                        }

                        for (int i = item.current + 1; i <= item.total; i++)
                        {
                            worker.QuerySinglePage(i, item.stockId);
                            using (stockdbaEntities db = new stockdbaEntities())
                            {
                                db.DailyWork.Where(o => o.receiveDate == item.receiveDate && o.stockId == item.stockId).First().currentPage = i;
                                db.ServiceLog.Add(new ServiceLog() { updateTime = DateTime.Now, updateLog = string.Format("Run:{0}:{1}/{2}", item.stockId, i, item.total) });
                                db.SaveChanges();
                            }
                            Thread.Sleep(10000);
                        }
                    }
                    catch (Exception ex)
                    {
                        using (stockdbaEntities db = new stockdbaEntities())
                        {
                            db.ServiceLog.Add(new ServiceLog() { updateTime = DateTime.Now, updateLog = String.Format("Run:{0}", ex.Message) });
                            db.SaveChanges();
                        }
                    }
                }
                Interlocked.Decrement(ref taskNum);
            });

            if (taskNum < 10)
            {
                nodeTask.Start();
                Interlocked.Increment(ref taskNum);
                return String.Format("New Task, TaskNum:{0}", taskNum);
            }

            return String.Format("TaskNum:{0}", taskNum);
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: homerch/StockAnalysis
 private void btnInit_Click(object sender, EventArgs e)
 {
     MainServiceReference.MainServiceSoapClient client = new MainServiceReference.MainServiceSoapClient();
     lbResult.Text = "...";
     lbResult.Text = client.RunInit();
 }
コード例 #3
0
        public string Run()
        {
            Task nodeTask = new Task(() =>
            {
                MainServiceReference.MainServiceSoapClient client = new MainServiceReference.MainServiceSoapClient();
                MainServiceReference.WorkItem item;

                StockQuery worker = new StockQuery();

                while ((item = client.GetWork()) != null)
                {
                    try
                    {
                        using (stockdbaEntities db = new stockdbaEntities())
                        {
                            db.ServiceLog.Add(new ServiceLog()
                            {
                                updateTime = DateTime.Now, updateLog = string.Format("Run:{0}", item.stockId)
                            });
                            db.SaveChanges();
                        }

                        for (int i = item.current + 1; i <= item.total; i++)
                        {
                            worker.QuerySinglePage(i, item.stockId);
                            using (stockdbaEntities db = new stockdbaEntities())
                            {
                                db.DailyWork.Where(o => o.receiveDate == item.receiveDate && o.stockId == item.stockId).First().currentPage = i;
                                db.ServiceLog.Add(new ServiceLog()
                                {
                                    updateTime = DateTime.Now, updateLog = string.Format("Run:{0}:{1}/{2}", item.stockId, i, item.total)
                                });
                                db.SaveChanges();
                            }
                            Thread.Sleep(10000);
                        }
                    }
                    catch (Exception ex)
                    {
                        using (stockdbaEntities db = new stockdbaEntities())
                        {
                            db.ServiceLog.Add(new ServiceLog()
                            {
                                updateTime = DateTime.Now, updateLog = String.Format("Run:{0}", ex.Message)
                            });
                            db.SaveChanges();
                        }
                    }
                }
                Interlocked.Decrement(ref taskNum);
            });

            if (taskNum < 10)
            {
                nodeTask.Start();
                Interlocked.Increment(ref taskNum);
                return(String.Format("New Task, TaskNum:{0}", taskNum));
            }

            return(String.Format("TaskNum:{0}", taskNum));
        }