|
aliarifpk wrote:
1- This is for .NET Framework not for .NET Compact Framework
Oh,sorry for that I didn't take attention to it.
aliarifpk wrote:
2- This code is for Mouse hooking not for keyboard
They follow the same procedure, you can find out yourself when you learn one.
Mazy
"A bank is a place that will lend you money if you can prove that you don't need it." - Bob Hope
|
|
|
|
|
Dear Mazy,
I am working on this task for last three days and the API's in .Net Framwork doesn't supported in .Net Compact Framework. That's why I am looking for some alternated which read the keyboard buffer and yet searching .... If someone has done this ... please let me know
Regards,
Muhammad Arif
|
|
|
|
|
Windows CE doesn't support message hooks. Hooking the keyboard isn't possible like it is under Windows 9x/2000/XP/2003.
RageInTheMachine9532
|
|
|
|
|
Dear Dave,
Can you provide me some authenticated URL which agree with your argument that Windows CE doesn't support hooking? I have to have a proof to my client for this argument.
Arif
Muhammad Arif
|
|
|
|
|
|
aliarifpk wrote:
This is for .NET Framework not for .NET Compact Framework
I don't think it make difference cause you have to call win32 API as you can see in that article, so I think you can use those API there too.
Mazy
"A bank is a place that will lend you money if you can prove that you don't need it." - Bob Hope
|
|
|
|
|
UserControl in VisualBasic 6.0 has
UserControl_AsyncReadComplete(AsyncProp As AsyncProperty) Event,
UserControl_AsyncReadProgress(AsyncProp As AsyncProperty) Event and
UserControl.AsyncRead() Method
To create in C#, I should use what class?
Note: The event and method I mention is very excellent, No side effect while downloading
Sorry for bad English.
Thank You.
|
|
|
|
|
What do you want to exactly do? and what is that UserControl? Those are Async. methods and in your class you don'm implement them, you just call them in your client like that.
Mazy
"A bank is a place that will lend you money if you can prove that you don't need it." - Bob Hope
|
|
|
|
|
hi,
I have some questions about making thread in my application, as I have no much experiences on Threading. Hope someone can help me.
In my application, I have a button function for outputing files. However, I need to generate some files and pictures before final step, the flow is simply like :
<br />
private void menuItem4_Click(object sender, System.EventArgs e)<br />
{<br />
....<br />
Main_generate_process();<br />
<br />
finalStep(); <br />
}<br />
The main problem is that before runing finalstep, I have to wait until the successful of Main_generate_process(), but I can't measure how long will the process take because the process is run in other DLL function, so I have an idea to use thread.
<br />
private void menuItem4_Click(object sender, System.EventArgs e)<br />
{<br />
....<br />
outThread = new Thread(new ThreadStart(ThreadProc));<br />
outThread.IsBackground = true;<br />
outThread.Start();<br />
<br />
do<br />
{ <br />
<br />
}while(this.outThread !=null);<br />
<br />
<br />
finalStep(); <br />
}<br />
<br />
public void ThreadProc()<br />
{ <br />
Main_generate_process();<br />
StopThread(); <br />
}<br />
<br />
private void StopThread()<br />
{<br />
if (this.outThread != null)<br />
{<br />
outThread.Interrupt();<br />
outThread = null;<br />
}<br />
}<br />
I found that the do-while loop also waste many times. Am I get a wrong idea?
The other quetion is :
can I call ThreadProc() directly in other function; i.e. if the thread has already started, and I need to run generate process again.
Thanks for help~~
|
|
|
|
|
The method Thread.Join() should exactly fit to your requirements. See MSDN for further information. Your code should look like that:
private void menuItem4_Click(object sender, System.EventArgs e)
{
....
//Start the background thread
outThread = new Thread(new ThreadStart(ThreadProc));
outThread.IsBackground = true;
outThread.Start();
outThread.Join();
}
public void ThreadProc()
{
Main_generate_process();
}
|
|
|
|
|
Thank you Troschi,
I have read and tried outThread.Join instead of using do-while loop, but Thread.Join() takes similar effect of do-while loop, it holds the main UI process, means caused the application in idle state.
I would like to run the process smoothly on background. so I need another good methods..
|
|
|
|
|
Maybe this could help you. It's not that elegant but it should work.
outThread.Start();
while (outThread.ThreadState != ThreadState.Terminated)
{
Application.DoEvents();
}
DoEvents-method will process all Windows messages currently in the message queue, so your application should not be idle.
Other solution could be raising an event before the outThread terminates.
|
|
|
|
|
THanks so much Troschi,
The code worked well, and the process does not held.
But will this method cause any hidden side effect?
I changed the code to :
outThread.Start();
while (outThread != null)
{
Application.DoEvents();
}
because I will call stopThread after processed the Thread function.
|
|
|
|
|
You should consider what Tom Larsen mentioned in his comments. Any use of multi threading could turn into a debugging nightmare. So I recommend you disable your menuitem while running the event handler, to prevent the user from starting it again before it finishes execution.
|
|
|
|
|
Try something like the following. I didn't test this so it may require some minor modifications.
private delegate void MyCallbackDelegate();
private void menuItem4_Click(object sender, System.EventArgs e)
{
outThread = new Thread(new ThreadStart(this.ThreadProc));
outThread.IsBackground = true;
outThread.Start();
}
private void ThreadProc()
{
Main_generate_process();
this.Invoke(new MyCallbackDelegate(this.InformUI));
}
private void InformUI()
{
}
|
|
|
|
|
The first thing you need to do is "join" the child process on the parent process. Doing this will insure that the parent will not proceed until the child processes have completed and therefore will call finalStep() at the right time.
The rest of the code snippet is unnecessarily complex. Just doing Thread.Join onto the parent thread should be more than enough syncronization. Threading topics like this can easily turn a simple task into a debugging nightmare. I would suggest you step back and read up on threading and the threading framework in .Net/C#.
|
|
|
|
|
I would avoid the use of Thread.Join in the UI thread because it is a blocking call. The UI thread will be unable to process messages during the execution of the worker thread. The whole reason for using a thread in the first place is keep the UI thread active.
|
|
|
|
|
Given the code snippet I am not even going to say I understand the user interaction. However, it looks like a user activated event. The user clicked on a menu item like "Run This..." Just the indictor that a "final step" is needed indicates that the system to be sane must be run in that order. There is no indication that UI events are handled asyncronously so why add that level of complexity and a different and somewhat advance form of bugs and debugging?
Or to put it another way, the user selects "Run This..." without Join so the application continues to be interactive. What is to stop the user from selecting again "Run This..."?
Its all hypothetical anyway. Neither of us know what the application does to make the right choice on action. I shy away from allowing the user choice of "forking" operations. We have a hard enough time making the right UI choices so that users will grasp the application easily. Adding "forking" invovles all sorts of complexity without much UI bang.
|
|
|
|
|
Is it possible to save the contents of a Rich Text Box to an XML File, including bold text, italics, etc? If not, could someone suggest an alternative way to do it?
Thanks in advance.
-Sean
|
|
|
|
|
Yes, but probably not like you're thinking. You could save the value of the RichTextBox.Rtf property in a CDATA section of an XML document, but it won't convert the RTF to XML like Word can do; for that, it takes a good filter. You could save the RTF, open it in Word, and save it as HTML (which is actually XHTML - or an XML schema that looks like HTML) from Word. Word 2003 can also save XML in a different schema than XHTML. There are articles here on CodeProject that cover such topics.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Ok, I've been a VB programmer for years and am pretty good at .NET (in the VB World). I can do most stuff in C# but there are a few holes in my knowladghe of C#.
I know the difference between Static and Non-Static methods but what I don't understand is, in what cases do you NEED to use a non-static?
As I see it you only need to use non-static if you need to instance a class as an object. But I am at a loss to see when you would absolutly need to use a non-static method.
I hope this makes sense, the reason it might not is couse I don't get this 100%.
Could somone please fill in the blanks, thanks
Matthew Hazlett
Windows 2000/2003 MCSE
Never got an MCSD, go figure...
|
|
|
|
|
Well, in Object Oriented programming to tend to have no static methods. Usually, static methods are shortcuts for constructors or for accessing singletons.
With static classes you cannot do virtual overloading which is a very important tool in OO.
While designing static method you should take good care of making them thread-safe. This is done by two ways: make the class have no static field or lock the class type before doing something.
Cheers
Jonathan de Halleux.
www.dotnetwiki.org
|
|
|
|
|
Matthew Hazlett wrote:
As I see it you only need to use non-static if you need to instance a class as an object. But I am at a loss to see when you would absolutly need to use a non-static method.
Ummm... Gosh, it's the first time I've seen that question - usually it's the other way round.
Let's say you have a class that represents a customer - You don't expect to only ever have one customer do you? Each customer is represented by an instance of the class. A static should only be used when it is going to be common to all customers. So, for instance a property called CustomerAccount should be a non-static because each customer has a different account number. However you may have a method called GenerateNewAccountNumber() which would be static because its result is not dependent on any single instance of the customer class. It might be combined with a static member variable (field) called NextAccountNumber so that each time it called the field is updated so that each subsequent call will generate a unique Account number (as you don't want two customers to have the same Account Number)
Does this help?
EuroCPian Spring 2004 Get Together[^]
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
|
|
|
|
|
Ok, then its kinda like I thought.
A static object is just a single entry analigus to the static variables in VB.
Is this to say if you have a non-static object like "Mailbox" and then create the object 5 times, If the object contains static methods each copy of the object will use the same method "prototype" (but diffrent data) ?
Matthew Hazlett
Windows 2000/2003 MCSE
Never got an MCSD, go figure...
|
|
|
|
|
Matthew Hazlett wrote:
If the object contains static methods each copy of the object will use the same method "prototype" (but diffrent data) ?
No, the static methods (or properties) can only access static data (fields/member variables) in the class.
Non-static methods (or properties) can access both static and non-static data in the class.
The static data in the class exists only once for the entire application, the non-static data applies once for each instance of the class because it may be different for each instance of the class.
EuroCPian Spring 2004 Get Together[^]
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
|
|
|
|