-
12-09-2012, 03:23 PM #1Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
gọi form application từ windown service như thế nào?
Mình có 1 form App, khi no chay len se load 1 so web browser , dong thoi se ghi lại URL cua nhung page đã load.
Giờ cần viết 1 windown service chạy ngầm bên dưới, mỗi 1 phút sẽ chay 1 lần.
Hiện tại Khi chạy windown service thì nó ko load được form , nhung lại ghi duoc cac URL ra file *.txt.
Code minh nhu sau, ai biet chi gium mình làm sao co the load duoc cả form len luon :
public partial class wsWebBrowser : ServiceBase
{
private ManualResetEvent _shutdownEvent = new ManualResetEvent(false);
private Thread _thread;
public wsWebBrowser()
{
InitializeComponent();
if (!(System.Diagnostics.EventLog.SourceExists("wsWeb Browser_Source")))
{
System.Diagnostics.EventLog.CreateEventSource("wsW ebBrowser_Source", "wsWebBrowser_Log");
}
wsWebBrowserEventLog.Source = "wsWebBrowser_Source";
wsWebBrowserEventLog.Log = "wsWebBrowser_Log";
}
protected override void OnStart(string[] args)
{
_thread = new Thread(exewsWebBrowser);
_thread.Name = "wsWebBrowser";
_thread.IsBackground = true;
_thread.Start();
}
private void exewsWebBrowser()
{
while (!_shutdownEvent.WaitOne(0))
{
ProcessStartInfo chuongtrinh = new ProcessStartInfo();
chuongtrinh.WorkingDirectory = @"E:\Projects\FrmWebBrowser\bin\Release";
chuongtrinh.FileName = "FrmWebBrowser.exe";
Process.Start(chuongtrinh);
_thread.Join(60000);
}
}
protected override void OnStop()
{
_shutdownEvent.Set();
if (!_thread.Join(3000))
{
_thread.Abort();
}
}
}View more random threads:
- Đồ án tiệm cầm đồ - Đầy đủ mã nguồn, viết bằng Visual C#
- Vẽ biểu đồ với điều khiển Chart trong Visual C#.NET 2010
- Những lưu ý bạn không thể bỏ qua khi mua macbook pro thiết kế đồ họa
- source code quản lý trung tâm gia sư bằng ASP.NET MVC 2 + ajax
- Mã nguồn C#, code bàn phím ảo viết bằng C#
- share bộ code office online
- Code game Magic Blocks
- Phần mềm quản lý tuổi thọ máy móc
- Demo: Lý thuyết đồ thị - Windows Form C# 2008
- điểm danh các laptop doanh nhân đẳng cấp nhất hiện nay
Trứng rung điều khiển từ xa Vibrator Spark Of Love Sản phẩm trứng rung bluetooth có điều khiển từ xa này được thiết kế với tông màu Rose Gold viền kim khí trải qua. kích tấc 7,4cm x 3,5cm giúp trứng...
TOP 3 trùy rung điều khiển từ xa...