|
Check this.[^]
I Love T-SQL
"Don't torture yourself,let the life to do it for you."
|
|
|
|
|
I'm creating a simple calculator.. so my calculator has only a textbox, it doesnt have any buttons so the user communicates with the calculator using the keyboard... so what i did is to enable the preview key down of the form and on the event of the key down, the computer is able to get the values entered from the keyboard. The problem with key down is that it only works if it has focus on the control or the form... but what i want is that even though the focus is not on the form or lets say the focus is on another application, how do i get my program to still get the keyboard values entered by the user?
|
|
|
|
|
|
yeah cause you know i'm doing like a computation while looking at the values at the other application and dont like doing the short cut keys using alt+tab or keep on clicking the calculator just to enter values. specially if its in full screen mode.
|
|
|
|
|
You have me imagining an applet that's always minimized and displays the calculation its caption.
|
|
|
|
|
Interesting, because I'm envisioning a keylogger.
|
|
|
|
|
I thought that at first, but it seems like a legit concept. I don't like flipping between a calculator and windows all the time.
|
|
|
|
|
There appears to be no way to use Threading.Interlocked methods to change the value of a boolean. There's Increment and Decrement for Ints, and Exchange<t> for reference types, but nothing for changing the value of a boolean in a thread-safe manner.
Is this not required? Are changes to booleans already threadsafe?
|
|
|
|
|
JoeRip wrote: Are changes to booleans already threadsafe?
Half the time, they are :P
Don't you just put a lock block over the code where you change it ?
Christian Graus
No longer a Microsoft MVP, but still happy to answer your questions.
|
|
|
|
|
You mean, have a lock object for every private field in my class? Or have a single lock object that I lock every time I change any private field in my class? The first seems excessive, and the second seems... anti-performant.
I thought the Interlocked methods WERE tiny little lock blocks, used in an atomic fashion....
Or am I missing something fundamental here?
|
|
|
|
|
Declare it as volatile. :P
|
|
|
|
|
I have to admit, I can't tell if either one of you is serious...
|
|
|
|
|
I didn't know there were interlock methods, I'd always just create an object in the same scope as the variable and do
lock(myLockingObject)
{
theBool = false;
}
Christian Graus
No longer a Microsoft MVP, but still happy to answer your questions.
|
|
|
|
|
Mark Churchill wrote: Declare it as volatile
I am not sure, but I think volatile doesn't make the type thread safe. It only allows to read the latest value written by other threads.
|
|
|
|
|
|
Access to all primitive types <=32 bit is atomic.
So reading and writing ints and bools is safe. But a "read-modify-write" operation is not atomic; so for integers, there's Interlocked.Increment etc.
Now, the only kind of "read-modify-write" I could image for bools is negating them. That's not safe.
But something like "if (!a) { a = true; }" is safe: if another thread happens to change the value between the "if (!a)" and the "a = true;", the only thing it can have done is setting a to true - but that's not going cause any problems, since we are about to set a to true anyway.
However, if you use the boolean for things like "run this code only once", then you have to lock/use Interlocked.CompareExchange to ensure that only the first thread to set the boolean to true runs the "run only once" code.
Remember that usually, there's no point in making all members of a class thread-safe, as combined operations need locking anyways, so the user of a class usually has to do his own locking.
E.g. given a thread-safe list, "if (!list.Contains(x)) list.Add(x);" is not thread-safe, so you need to "lock (list)" around every list access - but if you have to lock around every access, you could as well start with a non-thread-safe list.
|
|
|
|
|
Daniel Grunwald wrote: However, if you use the boolean for things like "run this code only once", then you have to lock/use Interlocked.CompareExchange to ensure that only the first thread to set the boolean to true runs the "run only once" code.
Remember that there is no Interlocked.CompareExchange for boolean types. You can use an INT and treat it like a boolean, but that's pretty inelegant.
Oddly enough, Microsoft has repeatedly chosen not to support booleans in the Interlocked methods, despite the many requests I found in their forums/Connection Feedbacks.
|
|
|
|
|
JoeRip wrote: You can use an INT and treat it like a boolean, but that's pretty inelegant.
That's what I do. If you need interlocked booleans frequently, create a custom bool type to make the calling code a bit more elegant:
public struct MyBoolean
{
public static readonly MyBoolean False = new MyBoolean(0);
public static readonly MyBoolean True = new MyBoolean(1);
int val;
private MyBoolean(int val) {
this.val = val;
}
public MyBoolean CompareExchange(MyBoolean value, MyBoolean comparand)
{
return new MyBoolean(Interlocked.CompareExchange(ref val, value.val, comparand.val));
}
public static implicit bool(MyBoolean a)
{
return a.val != 0;
}
public static implicit MyBoolean(bool a)
{
return a ? True : False;
}
public static bool operator ==(MyBoolean a, MyBoolean b)
{
return a.val == b.val;
}
}
|
|
|
|
|
Hello.
I have a question here.
Is it possible to create the following?
FTP Client(*) connects to FTP Server. Then using the connection that was established between them, the FTP Server now acts as FTP Client and the FTP Client as FTP Server, and can now access files on the (*).
If it's possible maybe i can try developing it...
Just trying to bypass router for the ingorant people.
|
|
|
|
|
Don't mind the (FTP).
I pretty good at sockets so i don't thing it would be that hard, if it can be done ofcourse.
|
|
|
|
|
Hello,
I am looking for a way to programatically edit the web.config file for the section below. Most importantly I will need to set the website login password to a certain value stored in the database. The password keeps changing in database whereas username remains the same. Can you please suggest a way this can be done in C# 2.0?
<authentication mode="Forms">
<forms loginurl="Login.aspx" timeout="60" protection="All">
<credentials passwordformat="Clear">
<user name="testuser" password="test123" />
</credentials>
</forms>
</authentication>
Thanks!
|
|
|
|
|
I reckon the folks in the ASP.NET forum may know the answer. I believe the answer is no, tho.
Christian Graus
No longer a Microsoft MVP, but still happy to answer your questions.
|
|
|
|
|
I created a proxy application that sits locally, and a web service that communicates with my local proxy. I pass in a website and it passes back the raw data, pretty basic.
What I can't figure out how to do is get the images back as well for the page.
Take google for example, the page comes back fine, but the banner doesn't.
Should I parse the incoming HTML for the image tag then do a seperate request for that image? If so, how would I get it to the currently viewed page?
Any Idea's?
Hope this makes sense.
|
|
|
|
|
Anyone with suggestions??
|
|
|
|
|
Hi,
I have got a MDI app where one of the childforms must be able to see the status of a RadioButton on a docked panel on the MDI from. I want too use the mousedown event on a child frmShow to draw lines on the form if the radPoly was clicked on the pnlTools on the parent MDI form. Please help with a simple code example.
Thanks
Ian
|
|
|
|