How to monitor a long-running program programmatically

What I’ve currently got can be summed up with this pseudo code:

public static void Main(string[] args)
{
    var listOfObjects = Database.GetObjectsToUploadToOnlineService();
    Parallel.ForEach(Upload)
}

private static void Upload(MyUploadObject obj)
{
    //Build object (takes a few milliseconds)
    //Format to JSON (takes a few more milliseconds)
    //Upload (can take up to a max of 10 minutes)
    //Wait for a response (can take up to a max of 10 minutes)
    //Save response to our database (takes a few milliseconds)
}

This program is just set up on our server as a scheduled task. We own the program and can do what we want with it. My question stems from a blog about making automated monitoring checks (I don’t have a link handy).

So that got me to think: How in the world can I modify my program so that I can fire up another “monitoring” program? Or should this change from being a console program to to say a WPF program that is hidden?

Overall, I would prefer to be able to just run a program on my computer that checks on the progress of the program through the network, so I don’t have to RDP into the server to check on its status (but it wouldn’t be the end of the world).

Overall, I suppose I would like to see a window that says something like: Process x of y so far, the following items are being processed. List the items in, like, a table and have them say like “Uploading” or “Waiting for response”. Maybe if I get crazy I could also how a queue of failed items (but that would just be extra).

My mind keeps leaning towards an event, but I can’t figure out how I would run a program that can subscribe and unsubscribe to a running program. Is this even possible?

3

What you need is a way to communicate between your programs that does not tie them to each other. There are a number of ways to do this, you could have the task write to a file and have to monitor read from the file, make the task available via WCF so the monitor can ‘poll’ for changes, use the network…

To avoid reinventing the wheel, have a look at the log4net logging targets If I were to implement something like this I would probably use log4net and log to UDP or Telnet and have the monitor on the other end connect to it. log4net takes care of everything for you, including not throwing exceptions when there is no monitor active.

1

From your comments I see you have a client/server database available, and you uploader already has a connection and write access? Then it would probably be easiest to add a “monitoring” or “status” table to the database and let your uploader report its progress there (log each “interesting” step there, probably the 5 steps you listed above).

To view the status, create a second program with GUI, which connects to the database and displays the status (for example, by polling in intervals of 1 minute). You can run that program on your local desktop, assumed it is possible to connect to the database from there.

Of course, when writing to a status table interfers with your database transactions, you might use a separate connection. You can also utilize a message queue mechanism like MSQM for it, but that might be an oversized solution for your simple case.

1

Just to build on @JDT’s answer, a common way to do this is writing messages to a message queue. Whenever something important happens in your application it would write a message and send it to the message queue. Typically the format of the message is XML or similar. It’s the queue writer.

The monitoring application reads (queue reader) the queue and picks the messages and processes them by saving them and analyzing the message versus prior messages or conditions. If a condition is met, the monitoring application will raise an alert signifying a potential problem.

This decouples your application from monitoring itself as it is just firing away messages. It’s up to the monitoring application to determine when based on the current messages that something good or bad has happened. Queue’s are used because they offer a good means to store the messages without loss.

You want to centralized messaging if there are multiple instances of your application running. If there is only 1 instance, then using other stores like the windows event log or a file can be sufficient.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật