|
Hi. I have created a thread that calls Thread.Sleep(60000) after doing some work, and then it does some more work.
What I wanted to do is to make the thread to resume processing and not having to wait the 60000ms until the sleep ends.
For example, a function that tests if the thread is asleep, and if so, wakes it up. Is there a way to do this? I tried with the 'Resume' function, but this works only if the thread is in 'suspended' state.
Thanks.
|
|
|
|
|
Try to "Suspend" thread insted of "Sleep".
My english is not so good. Please, correct my errors.
Best regards, Alexey.
|
|
|
|
|
Thanks for the advice, but Suspend just suspends the thread infinitely.
The normal behaviour of the thread should be:
DoSomeWork
Thread.Sleep(60000)
DoSomeMoreWork
But in certain occasions I need to tell the thread to execute 'DoSomeMoreWork' before the sleep ends, that is, tell it to stop sleeping and continue execution.
|
|
|
|
|
Just put it in another thread instead of in main thread. Use some flag, for example "isFinished" or something like that.
DoSomeWork
while(isFinished == false)
{
... waiting...
}
DoSomeMoreWork
|
|
|
|
|
Use timer to manage this situation.
My english is not so good. Please, correct my errors.
Best regards, Alexey.
|
|
|
|
|
Use .net synchronisation mechanism . If u want ur worker thread to wait for a specific event use wait handles for the same. It is recomended not to use sleep to get the necessary syncronisation.
|
|
|
|
|
Use one of the many synchronization objects that .NET provides. Take a look at AutoResetEvent[^], ManualResetEvent[^] and Mutex[^]. In all the cases, you would have to do something like
Thread A
--------
DoX();
syncObject.WaitOne();
DoY();
Thread B
--------
DoP();
syncObject.Release();
DoQ(); The advantage of using synchronization objects instead of looping with a flag is that threads waiting on a synchronization primitive do not consume CPU cycles. Windows knows about synchronization primitives and so doesn't schedule the thread for execution until the sync object is signalled. With looping, Windows is forced to schedule that thread and it uses up its time slice looping.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
I´d like to write a Program in C#. But I need to integrate existing c++ classes. Principally this should be possible, but I´ve no Idea how to manage this.
Can anybody give me some hints how to start or can anybody give me a Link to a useful Tutorial?
Thanks a lot!
|
|
|
|
|
You can implement COM interfaces on your c++ classes, then import COM objects in C# and use it. Read C# books most of them tells how to work with COM. Also you need to read some C++ books on COM.
My english is not so good. Please, correct my errors.
Best regards, Alexey.
|
|
|
|
|
I think this article could help you:
http://www.codeproject.com/useritems/usingcppdll.asp
|
|
|
|
|
the problem here is that (i) is a unsigned long long, and all the squar funktions i can find is only operating in duble or long duble....
I woud make one my selv, butt all the ways of calculating the squar of (i) i coud find uses some trial and error. is it not posserble to calculate theis wiith out a trial and error method, as i see this as a time theif.
a *.h file will be geat, but as i hope to go further than just unsigned long long, a way of calculating it woud be even better.
regards t
|
|
|
|
|
Why not do some converting?
ulong value = 4;
ulong sqrt = Convert.ToUInt64(Math.Sqrt(value));
|
|
|
|
|
Is an iterative method (trial and error) but it works and is fairly efficient.
A man said to the universe:
"Sir I exist!"
"However," replied the Universe, "The fact has not created in me A sense of obligation."
-- Stephen Crane
|
|
|
|
|
hi all,in my web application i provide the option for searching the records which are present in the database.Initially(a week after deploying ) this wont make any problem for me but the records in the database are now closer to 1000,and it loads slowly and take more time to display the result in the grid,i feel in future it will take more and more time to load,how to speedup my application while searching.
Regards,
ayyp
|
|
|
|
|
Hi ayyp,
You could make of custom paging in datagrid so that it fetches only what is required.There is a very good article on this on codeproject.Go thorough that and if you find any other method do inform me as I am also doing the same thing.Here is the article link http://www.codeproject.com/aspnet/PagingLarge.asp
|
|
|
|
|
You will have to describe how you are performing the search and what the actual bottleneck is. Is it the actual search function or the display of the results? Are yuo using a Select statement to get your data? Have you created an index on the columns you are searching?
|
|
|
|
|
thanks for u replay, and here, i didn't use any index for my table i just use the select statement to fetch the record according to the input given by the user from the textbox,dropdownlist,...(here i just append the inputs to the query string and enter the final sting into the sqlcommand).is this the reason for the delay...?
Regards,
ayyp
|
|
|
|
|
You mean something like
string sqlQuery = "SELECT * FROM SomeTable WHERE SomeColumn = '" + _myTextBox.Text + "'";
?
You should try to find out whether it is really the sql command which is slowing things down. If yes then created indices on the columns you use in your where clause.
|
|
|
|
|
Ok this is what im trying to achive. A random number that conforms to a distrobution pattern, for example the normal distrobution where most of the numbers are around the center and as you move away from that point their frequency becomes less. e.g range 1-10 5 is the mean most numbers would end up around 4,5,6 where only a handfull would be 1 or 10.
dose anyone know of either a libary or a calculation to achive these sorts of results? or maybe some for of normal distrobution table?
any input or help would be greate
Ant
|
|
|
|
|
The following should do what your looking for. Some information on the normal distribution e.g. the meaning of parameters my and sigma here[^].
public class NormalDistribution : IDistribution
{
public double sigma;
public double my;
private Random generator;
private double help1;
private bool help2;
public NormalDistribution()
{
this.my = 1.0;
this.sigma = 1.0;
this.generator = new Random();
this.help1 = 0.0;
this.help2 = false;
}
public double Next()
{
if (this.help2)
{
this.help2 = false;
return this.help1;
}
else
{
for (; ; )
{
double v1 = 2 * this.generator.NextDouble() - 1;
double v2 = 2 * this.generator.NextDouble() - 1;
double w = v1 * v1 + v2 * v2;
if (w <= 1)
{
double y = Math.Sqrt(-2 * Math.Log(w) / w);
this.help1 = v2 * y * this.sigma + this.my;
this.help2 = true;
return v1 * y * this.sigma + this.my;
}
}
}
}
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook
www.troschuetz.de
|
|
|
|
|
i want ot us System.Windows namespace but it was not available there. after System. there r only web is available means (System.Web) no other option with W so how can i get the System.Windows name space
|
|
|
|
|
Are you working on a Windows application?
Pramod
|
|
|
|
|
yes on windows n want to try in on console
|
|
|
|
|
See at your reference, you must have a reference to System.Windows.Forms.dll
|
|
|
|
|