• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 468
  • Last Modified:

C# DLL Modalless Forms tab problem.

i wrote a c# DLL and i was create a form into DLL. my form has textarea. Form is modalless.I
I show form and i did see broken tab key. Because of this reason, I wrote this code below. Bu My cpu go to crazy like %50 CPU using when code go to Application.DoEvents.After that i try to use PeekMessage for controling incoming message. Bu t i didnt solve this question. can someone help me about performance optimization in here.


TestForm myForm;
myForm = new TestForm();
myForm.Show();
            while (!myForm.IsDisposed)
            {     
              Application.DoEvents();                                                                                                         
            }

Open in new window

0
vtokmak
Asked:
vtokmak
  • 3
  • 3
1 Solution
 
MerijnBSr. Software EngineerCommented:
> After that i try to use PeekMessage for controling incoming message. Bu t i didnt solve this question.

You should use GetMessage() instead of PeekMessage().
You get high CPU usage (50%, dual core by any change?) because your code is running in circles like crazy, PeekMessage() doesn't wait or anything. GetMessage() actually waits until there _is_ a message to process. Be aware though that GetMessage() actually removes the message from the queue where PeekMessage() can also leave it.
0
 
MerijnBSr. Software EngineerCommented:
Other option could be to place a little delay in your while loop...
0
 
vtokmakAuthor Commented:
i tried GetMessage here like

TestForm myForm;
myForm = new TestForm();
myForm.Show();
            while (!myForm.IsDisposed)
            {    
                 if GetMessage(&msg,FormHandle,0,0)
                   {
                     Application.DoEvents();    
                   }                                                                                                    
            }
I saw there, My CPU problem solved but i lost tab events :)
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
vtokmakAuthor Commented:
When i try to delay like sleep(10) , i saw , my form flicking when i wrote someting on textbox. I need to capture tabchange events with normal CPU usage
0
 
MerijnBSr. Software EngineerCommented:
Please try this (pseudo code!):
TestForm myForm;
myForm = new TestForm();
myForm.Show();
            while (!myForm.IsDisposed)
            {     
              if (!PeekMessage())
                WaitMessage();
              Application.DoEvents();                                                                                                         
            }

Open in new window

0
 
vtokmakAuthor Commented:
nothing. I discuss some people from microsoft about this problem. I are not support COM DLL for this works. we can only use this style on Internet Explorer. Basic solution is Sleep after While loop. I try to Sleep(250) sound is good.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now