private void UpdateStAuto()
{
SQLiteHelper sqlite = new SQLiteHelper();
sqlite.CloseConn();
//sqlite.CreateTable("mindetail", "code VARCHAR,stockname VARCHAR,time DateTime,tradtime VARCHAR,type VARCHAR,price DOUBLE,num INT,Turnover DOUBLE,message VARCHAR");
//sqlite.CreateTable("mindetailall", "code VARCHAR,stockname VARCHAR,time DateTime,price DOUBLE,num INT,Turnover DOUBLE,nums INT,type VARCHAR");
sqlite.CreateTable("mindetail", sqlitemindetail.createcols());
sqlite.CreateTable("mindetailall", sqlitemindetailall.createcols());
runstatus = "正在初始化数据列表";
Thread t = new Thread(new ThreadStart(delegate
{
Application.Run(new 弹窗之正在处理("正在初始化数据列表"));
}));
Random ran = new Random();
int RandKey = ran.Next(100, 9999);
t.Name = "T_" + DateTime.Now.ToString("yyyyMMddhhmmss") + RandKey;
t.Start();
common.threadTips.Add(t.Name, false);
stockData stkdata = new stockData();
string[] codes=codename.Keys.Join(",").Split(',');
stockTTM.Clear();
stocklastprice.Clear();
stockGPA.Clear();
stockCapital.Clear();
int len = 500;
if (codes.Length> len)
{
for (int ic = 0; ic < codes.Length; ic+=0)
{
if (codes.Length - ic < len) len = codes.Length - ic;
string[] tmpcodes = new string[len];
for(int ib=0;ib<500 && ic < codes.Length; ib++)
{
tmpcodes[ib] = codes[ic];
ic++;
}
//codes.CopyTo(tmpcodes,0);
Dictionary<string, string> tmpdic;
tmpdic = stkdata.GetTTM(tmpcodes);
if(tmpdic != null)
stockTTM = stockTTM.Concat(tmpdic).ToDictionary(k => k.Key, v => v.Value);
tmpdic = stkdata.GetLastDayPrice(tmpcodes);
if (tmpdic != null)
stocklastprice = stocklastprice.Concat(tmpdic).ToDictionary(k => k.Key, v => v.Value);
tmpdic = stkdata.GetGPA(tmpcodes);
if (tmpdic != null)
stockGPA = stockGPA.Concat(tmpdic).ToDictionary(k => k.Key, v => v.Value);
tmpdic = stkdata.GetCapital(tmpcodes);
if (tmpdic != null)
stockCapital = stockCapital.Concat(tmpdic).ToDictionary(k => k.Key, v => v.Value);
//stockTTM = stockTTM.Concat(stkdata.GetTTM(tmpcodes)).ToDictionary(k => k.Key, v => v.Value);
//stocklastprice = stocklastprice.Concat(stkdata.GetLastDayPrice(tmpcodes)).ToDictionary(k => k.Key, v => v.Value);
//stockGPA = stockGPA.Concat(stkdata.GetGPA(tmpcodes)).ToDictionary(k => k.Key, v => v.Value);
//stockCapital = stockCapital.Concat(stkdata.GetCapital(tmpcodes)).ToDictionary(k => k.Key, v => v.Value);
}
}
else
{
stockTTM = stkdata.GetTTM(codes);
stocklastprice = stkdata.GetLastDayPrice(codes);
stockGPA = stkdata.GetGPA(codes);
stockCapital = stkdata.GetCapital(codes);
}
runstatus = "初始化";
for (int l = 0; l < dgvlist.Rows.Count; l++)
{
SetThreadStatus setstatus = new SetThreadStatus(SetThreadStatuMethed);
this.BeginInvoke(setstatus, dgvlist.Rows[l].Cells["代码"].Value, "初始化");
}
int cnt = 0;
List<string> keys = new List<string>(codename.Keys);
if (useDB)
{
cnt = dgvlist.Rows.Count;
}
else
{
cnt = keys.Count;
}
common.threadTips[t.Name] = true;
int i = 0;
while (i < cnt)
{
if ( ParallelsMindetail >= int.Parse(common.nullstr2(txtThreadNum.Text,"50")) )
{
//Console.WriteLine("分时明细线程数已达最大,等待。。。。");
continue;
}
if (stockMinDetailOnLine.pause)
{
runstatus = "暂停";
Thread.Sleep(5000);
continue;
}
if (stockMinDetailOnLine.stop)
{
break;
}
//进程占用内存超过2G,可能为sqlite内存数据库内存泄露,需处理
if(common.GetMemoryMB("",true)>2048)
{
Thread thread = new Thread(new ThreadStart(sqlite.memFree));
thread.Name = "memFree" + keys[i];
thread.Start();
}
labelstkcnt.Text = "个股数"+(i+1) + "/" + cnt;
string stkcode = keys[i];
runstatus = "运行";
//优先处理手动运行的
if (starthread.Count>0)
{
stkcode = starthread.Keys.First();
stockMinDetailOnLine priority = new stockMinDetailOnLine(stkcode, false, true, false, false, 0);
priority.f1 = this;
Thread priorityTT = new Thread(new ThreadStart(priority.GetMinDetailTradeFromWeb));
priorityTT.Name = "" + stkcode;
priorityTT.Start();
starthread.Remove(stkcode);
continue;
}
//已获取过数据,跳过
int dgvidx = GetIdx(stkcode);
if (dgvlist.Rows[dgvidx].Cells["状态"].Value != null)
{
i++;
continue;
}
stockMinDetailOnLine stkmin = new stockMinDetailOnLine(stkcode, false, true,false, false,0);
stkmin.f1 = this;
Thread TT = new Thread(new ThreadStart(stkmin.GetMinDetailTradeFromWeb));
TT.Name = "" + stkcode;
TT.Start();
i++;
//System.Threading.Thread.Sleep(200);
System.Threading.Thread.Sleep((1/ trackBar1.Value)*1000);
GC.Collect();
}
runstatus = "循环完成";
while(1==1)//用于循环完成后,手动启动
{
runstatus = "运行等待";
if (stockMinDetailOnLine.pause)
{
runstatus = "暂停";
Thread.Sleep(5000);
continue;
}
if (stockMinDetailOnLine.stop)
{
runstatus = "退出";
break;
}
if (分时明细监控.ParallelsMindetail==0 &&DateTime.Now> DateTime.Parse("15:05:00"))
{
runstatus = "退出";
break;
}
if (starthread.Count == 0) continue;
var stkcode = starthread.Keys.First();
stockMinDetailOnLine manual = new stockMinDetailOnLine(stkcode, false, true, false, false, 0);
manual.f1 = this;
Thread manualTT = new Thread(new ThreadStart(manual.GetMinDetailTradeFromWeb));
manualTT.Name = "" + stkcode;
manualTT.Start();
starthread.Remove(stkcode);
}
Console.WriteLine("getcnt:"+getcnt);
}
UpdateStAuto()
于 2022-11-09 14:29:53 首次发布