Pages

Showing posts with label C#. Show all posts
Showing posts with label C#. Show all posts

Friday, December 25, 2009

Polling data/performing analysis continuously at regular intervals

Summary:
In .net, I have discovered two methods for polling data/performing some kind of continuous analysis at regular intervals.
First approach is to use Global.asax file and start a timer in it when the application starts. However, it stops doing the job when thread is idle for some time i.e. there are no requests. This will be performing task at regular intervals only when users are continuously using the information.

Second approach is to use WindowServices. Using an installer, the windows service can be installed to the Windows Services. This service can be configured to run continuously.

I preferred the second approach as the websites are meant for UI only so it is better to perform regular interval tasks in a separate application, and also due to the problem I stated above.

Details:
Coming soon….

Friday, January 2, 2009

Processes with C#

Something that's not of much interest to me right now. I knew about it but never found any application so I never used it.


Process graph= new Process();
graph.StartInfo.FileName = "C:\\Program
Files\\Graph\\Graph.exe";
//graph.StartInfo.Arguments = "any
arugment";
graph.Start();


Starts Graph process. With additional properties, you can set it to run in the background.


Process[] processlist = Process.GetProcesses();
foreach (Process theprocess
in processlist)
{
Console.WriteLine("Process: {0} ID: {1}",
theprocess.ProcessName, theprocess.Id);
}

This gets all the processes and displays some information about them.

See the documentation for more information. It's pretty simple and there isn't anything interesting in my opionion. Threads are bit more interesting ...

Thursday, January 1, 2009

Merging several files in different directories under one single directory

I had many directories under one directory with some files in each of them and I wanted to merge all the files together in a single directory. I created following C# file in a console application that has a _MoveFiles static method which peforms all the work.

Example Usage:

class Program
{
static void Main(string[] args)
{
string[] notToInclude = { "C:\\Program Files\\abc" };
MoveFiles._MoveFiles("C:\\Program Files\\abc",
"C:\\Program Files\\abc_target",
notToInclude,
null,
null,
false);
}
}

You can pass several criteria to define which directories to choose and which to ignore and which file extensions should be picked. And, if in the end the program should attempt to delete the directory (only possible if the directory gets empty).

MoveFiles

It can be further imporved but I have finished my work :)