|
Oh, he's on my Watch List big time now.

|
|
|
|
|
Yeah, after looking at this guys history, I see what you mean.
Has this putz ever heard of Google?
|
|
|
|
|
I have to start timer at 12AM daily. It has to execute 4 items i have with 15min interval
i.e, item1 should be executed @12, item2 @12 15 and so on
i have written below code:
To start timer @12Am :-
private void SetTimerValue()
{
//// trigger the event at 12 AM.
DateTime requiredTime = DateTime.Today.AddHours(0).AddMinutes(00);
if (DateTime.Now > requiredTime)
{
requiredTime = requiredTime.AddDays(1);
}
TimeSpan periodTS = requiredTime - DateTime.Now;
myTimer = new System.Threading.Timer(new TimerCallback(TimerAction), null, 0, (long)periodTS.TotalMilliseconds);
}
In TimerAction i have 4 items which has to be called @ 15min interval
public void TimerAction(object e)
{
var collection = new List<string> { "item1", "item2", "item3", item4" };
// When timer is 12am, execute item1
// When timer is 12 15am, execute item2
// When timer is 12 30am, execute item3
// When timer is 12 45am, execute item4
}
My question is :
1. Can i create seperate timer inside TimerAction method?
2. How should i loop and execute all these 4 items?
3. Is there any better approach?. Please guide me to do this.
|
|
|
|
|
Avoid generating new timers at all - they are a scarce resource, so you should try to keep them to a minimum.
A much, much better approach is to use a single timer, that has a smaller interval: 15 minutes, or maybe five minutes.
You then check the current DateTime against the main trigger time - 12 AM - and set a new time for the next task - 12:15.
When you hit (or pass) that time, you execute your task, and set the next time to 12:30, and so on.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
how to stop the timer after 12 45. how can i check each item at specific time...can u pls show me in code
|
|
|
|
|
Member 11074115 wrote: how to stop the timer after 12 45
Easy - set the initial timer to tomorrow 12 AM.
That way the whole sequence starts again the next day (assuming the program is still running)
Member 11074115 wrote: how can i check each item at specific time...can u pls show me in code
Oh, come on!
You know how to add 15 minutes to a DateTime - or you should.
You know how to fetch the current date and time.
And you know how to compare two DateTime values.
So what part of this is complicated?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
i have already written code to trigger @12, but in TimerAction i am not able to get the timer time. How to fetch that value so i can check for each item.
Here am setting timer
private void SetTimerValue()
{
//// trigger the event at 12 AM.
DateTime requiredTime = DateTime.Today.AddHours(0).AddMinutes(00);
if (DateTime.Now > requiredTime)
{
requiredTime = requiredTime.AddDays(1);
}
TimeSpan periodTS = requiredTime - DateTime.Now;
myTimer = new System.Threading.Timer(new TimerCallback(TimerAction), null, 0, (long)periodTS.TotalMilliseconds);
}
But in TimerAction i shud loop items and set interval....i dono how to do that..wer shud i set interval
ublic void TimerAction(object e)
{
var collection = new List<string> { "item1", "item2", "item3", "item4" };
// When timer is 12am, execute item1
// When timer is 12 15am, execute item2
// When timer is 12 30am, execute item3
// When timer is 12 45am, execute item4
}
|
|
|
|
|
Don't.
Do this:
private enum Action
{
Disabled, Item1, Item2, Item3, Item4
}
private DateTime doAfter = DateTime.MaxValue;
private Action action = Action.Disabled;
This gives you the framework you need.
Then, set up and start the timer:
private void SetTimer()
{
Timer timer = new Timer();
timer.Interval = 1000 * 60 * 5;
timer.Tick += new EventHandler(timer_Tick);
timer.Start();
action = Action.Item1;
doAfter = DateTime.Now.Date.AddDays(1);
} And then handle the Tick:
private void timer_Tick(object sender, EventArgs e)
{
if (DateTime.Now >= doAfter)
{
switch (action)
{
case Action.Item1:
action = Action.Item2;
doAfter = doAfter.AddMinutes(15);
break;
...
case Action.Item4:
action = Action.Item1;
doAfter = DateTime.Now.Date.AddDays(1);
break;
}
}
}
And it handles it all for you.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
i have written below code, but it never triggers OnTimedEvent event. i should debug and test the code inside OnTimedEvent. How should i do this
private void SetTimer(TimeSpan interval)
{
timer = new System.Timers.Timer();
timer.Interval = 1000 * 60 * 5; // 5 minutes
timer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
timer.Start();
}
private void OnTimedEvent(object source, ElapsedEventArgs e)
{
// want to debug and test the code written here.
}
|
|
|
|
|
How can I implement this so it works properly?
Main thread creates an instance of Foo(). Foo() has a method Go(). I want Go() to be fire-and-forget, but I want ALL Go()'s to run before the process is allowed to exit, but I want that all encapsulated in Foo(). So...
I want:
main()
{
Foo f = new Foo();
for (int i = 0; i <= 200; i++)
f.Go();
}
That's all that the caller should do. No waits, no sleeps, no usings, nothing. Assuming thats possible.
so I tried using a queue where Go() adds an item to the queue and the Foo constructor spawns a thread that monitors the queue.
So it does work, but the worker thread is dying before it's done.
I tried putting a .Wait() on the task in ~Foo(), but the process still exits.
Also tried old school Thread, but then it never even seems to hit the ~Foo(). The main thread is now waiting on the worker thread to finish, but the worker thread is supposed to run for the life of Foo(), I would have expected main() to determine and try to kill Foo() and have it block in the finalizer???
modified 10-Sep-14 16:34pm.
|
|
|
|
|
|
No, I want the app to NOT exit after spawning off threads...
1) main thread creates instance of Foo()
2) for (1..1000) Foo.Go() should be a fire and forget unit of work
3) main thread "exits", but only unit of work 1..30 were processed because the main thread exited too fast
What I want instead is:
1) main thread creates instance of Foo()
2) for (1..1000) Foo.Go() should be a fire and forget unit of work
3) main thread "exits", BUT "PROCESS HANGS" until all 1000 units of work are completed
I know I can do this with a .Join in the main thread, but as I said in my original post is that Foo() is its own man. If it wants to "block the process from exiting" until all the work is completed, it should do so without the main threads assistance.
Seems like when *Tasks* are running, they don't block the process from exiting
Seems like when a *Thread* object is running, it blocks the process from exiting
I kind of got something working, but I'm not super happy with it.
I kick off a Thread so the process is blocked from exiting... the background thread does a BlockingCollection.Take with a cancellation token. If the cancellation token is set, it exits the background thread.
Meanwhile, I also kick off a main thread watch dog task that checks if the main thread has exited and if it does, AND the queue is empty it sets the cancellation token so the background thread can exit.
It does have the behavior I want, but I'm not really liking this part:
Thread threadCurrent = Thread.CurrentThread;
Task.Run(() =>
{
if (System.Diagnostics.Debugger.IsAttached)
threadCurrent.Join();
Console.WriteLine("EXITED");
while (_queueLogEntries.Count > 0)
{
Thread.Sleep(100);
}
Console.WriteLine("EXITED2");
_cts.Cancel();
});
|
|
|
|
|
You should be able to use Join in Go.
1) main thread creates instance of Foo()
2) for (1..1000) Foo.Go() should be a fire and forget unit of work
2.1) Go uses Join to wait until all threads are complete, then exits
3) main thread "exits" , BUT "PROCESS HANGS" until all 1000 units of work are completed
You can't have the main thread exit and "hang" at the same time.
|
|
|
|
|
i want make simple web browser by c# application.the browser i want to set fit to screen as in the image.
|
|
|
|
|
|
thanx Eddy for link..but i want to make browser with zoom out and zoom in facility....can you give me some idea with demo how can i do it...
|
|
|
|
|
Press Ctrl-+, should be supported by the COM-control.
If not, inject a zoom-tag in the body's style-tag.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
can u show me demo...tnx for tht
|
|
|
|
|
No.
Someone else might 
|
|
|
|
|
ok thnx for giving ur pricious time....
|
|
|
|
|
I'am trouble to implement encryption testing without times in millisecond and how i adding to the code??
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Security.Cryptography;
namespace RSAEncryption
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
#region-----Encryptionand Decryption Function-----
static public byte[] Encryption(byte[] Data, RSAParameters RSAKey, bool DoOAEPPadding)
{
try
{
byte[] encryptedData;
using (RSACryptoServiceProvider RSA = new RSACryptoServiceProvider())
{
RSA.ImportParameters(RSAKey);
encryptedData = RSA.Encrypt(Data, DoOAEPPadding);
}
return encryptedData;
}
catch (CryptographicException e)
{
Console.WriteLine(e.Message);
return null;
}
}
static public byte[] Decryption(byte[] Data, RSAParameters RSAKey, bool DoOAEPPadding)
{
try
{
byte[] decryptedData;
using (RSACryptoServiceProvider RSA = new RSACryptoServiceProvider())
{
RSA.ImportParameters(RSAKey);
decryptedData = RSA.Decrypt(Data, DoOAEPPadding);
}
return decryptedData;
}
catch (CryptographicException e)
{
Console.WriteLine(e.ToString());
return null;
}
}
#endregion
#region--variables area
UnicodeEncoding ByteConverter = new UnicodeEncoding();
RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();
byte[] plaintext;
byte[] encryptedtext;
#endregion
#region-- Function Implemantation
private void Encrypt_Click(object sender, EventArgs e)
{
plaintext = ByteConverter.GetBytes(txtplain.Text);
encryptedtext = Encryption(plaintext, RSA.ExportParameters(false), false);
txtencrypt.Text = ByteConverter.GetString(encryptedtext);
}
private void Decrypt_Click(object sender, EventArgs e)
{
byte[] decryptedtex = Decryption(encryptedtext, RSA.ExportParameters(true), false);
txtdecrypt.Text = ByteConverter.GetString(decryptedtex);
}
#endregion
}
}
|
|
|
|
|
|
I mean, adding one textbox and while to running to the textbox in the timers range 0-2000 millisecond 
|
|
|
|
|
|
I mean, adding one textbox and while to running to the textbox in the timers range 0-2000 millisecond 
modified 11-Sep-14 7:50am.
|
|
|
|
|