public void CreteTask(Action ready)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
var form = new Form
{
AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F),
AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font,
ClientSize = new System.Drawing.Size(525, 427),
Name = "Form1",
Text = "爬虫",
ControlBox = false,
ShowInTaskbar = false
};
_browser = new WebBrowser
{
Dock = System.Windows.Forms.DockStyle.Fill,
Location = new System.Drawing.Point(0, 0),
ScriptErrorsSuppressed = true,
};
_browser.DocumentCompleted += (s, e) =>
{
form.Text = string.Format("{0}", _browser.Url);
if (_documentCompletedEventList != null)
foreach (var handle in _documentCompletedEventList)
handle(s, e);
};
var _timer = new System.Windows.Forms.Timer()
{
Interval = 10,
Enabled = true
};
form.Controls.Add(_browser);
_timer.Tick += (s, e) =>
{
form.Close();
_timer.Stop();
};
form.Load += (s, e) =>
{
_timer.Start();
};
form.FormClosing += (s, e) =>
{
ready();
e.Cancel = true;
};
form.Activated += (s, e) =>
{
//此处可以将窗口隐藏
//form.Hide();
};
Application.Run(form);
}