|
Reflector is your friend:
public static void DoEvents()
{
ThreadContext.FromCurrent().RunMessageLoop(2, null);
}
If you keep poking deeper, you see that it's just running a message loop to handle any messages that might have been sent.
|
|
|
|
|
I beleive DoEvents call moves the pointer on the call stack to where the Windows Messages are, saving the current point and then returning to it after the windows messages are processed.
Of course not this over simplified but I beleive the logic works this way...
|
|
|
|
|
That is not correct. The Windows Message queue is not "on" the stack. No weird call stack operations are performed.
For .Net Application.Run() and Application.DoEvents() are somewhat similar in that they both call a message pump. A message pump could be very simply be:
MessagePump()
{
while ( true )
{
Message msg = GetMessage();
DispatchMessage( msg );
if ( msg.Msg == WM_QUIT ) break;
}
}
The code behind DispatchMessage will eventually call your events, e.g. when a button is clicked.
If you then do a form.ShowDialog() it will re-enter the message pump function (recursively, the previous call just stays on the call stack).
This is why showing a message box in a timer event handler will result in stacking up message boxes until resources are exhausted or a stack overflow occurs.
The call stack will look something like this (looking at it top-down) :
Application.Run
MessagePump
DispatchMessage
... framework stuff ...
Timer1.TimerEvent
SomeForm.ShowDialog
Application.DoEvents
MessagePump
DispatchMessage
... framework stuff ...
Timer1.TimerEvent
SomeForm.ShowDialog <-- if you indeed do this call then this will repeat until...
modified on Wednesday, September 8, 2010 2:36 PM
|
|
|
|
|
That's exactly what I meant, for example, if our heavy processing code is inside DispatchMessage, it might simply do "Goto address 1" as exemplified below and push the current address on the stack so it can be popped after the goto call finishes:
MessagePump()
{
while ( true )
{
Adr 1 Message msg = GetMessage();
Adr 2 DispatchMessage( msg );
Adr 3 if ( msg.Msg == WM_QUIT ) break;
}
}
Again, that's how I think it works.
|
|
|
|
|
This is low level Windows API view, not sure how dotNET sits on top.
1. Each Thread can have its own message pump if needed. If you have windows created on multiple threads, they can run separately. (97% sure)
2. A modal dialog must provide a new message pump, because it is called from the current stack of the "calling" message pump. The "calling" message pump is frozen until the modal dialog's pump exits. This is how you can get a return value from the Modal dialog during the event dispatching of the calling pump. This is also the case with Menus. The event handler for the menu is called from a different pump.
3. Prior to Windows XP(?), the only way to share the cpu with other Windows apps was when calling GetMessage() or PeekMessage(). It really was "play nice or don't play at all." You had to make sure that you "chunked" background work in such a way that you invoked PeekMessage() occasionally.
I am pretty sure that even Windows 95/98?/ME? were 32bit wrappers around the same old Windows 1.0 core. Pre-emption was enforced on DOS virtual machines, but all Windows apps ran in the same VM. This was great because you could actually locate and read memory structures out of other running programs on the system! WinNT families were pre-emptive and full protected memory spaces out of the starting block. There is probably a windows genealogy somewhere that says when certain features were introduced when.
|
|
|
|
|
I'm surprised that no one has pointed to MSDN for this: http://msdn.microsoft.com/en-us/library/system.windows.forms.application.doevents.aspx[^]
I know MSDN isn't always helpful, but it tells you what it does as well as when to use it and when not to use it.
Realistically, most circumstances where it is not safe to call DoEvents indicates that you are doing something wrong (such as raising the event in its own handler). Note: the emphasis is on "most" since there are exceptions to almost every rule.
I don't claim to be a know it all, for I know that I am not...
I usually have an answer though.
|
|
|
|
|
MSDN unforunately doesn't say HOW it does it, which was what I wanted to know.
I pretty much always check MSDN; I find it very helpful.
I already have a lot of experience using DoEvents in a correct way in VB6. With .NET I much prefer a worker thread though, for many reasons.
Thanks for all the responses
|
|
|
|
|
Hello All ,
I have used a CalendarExtender in my page with textboxes. When I press enter key in another textbox, calendar's popup is appearing.
I have used defaultbutton attribute in form tag and tried keeping my button id as defalut button but this is also not working.
Please help me out in same..
Thanks In Advance
|
|
|
|
|
Sorry, but you chose the wrong forum for your repost. You should be asking this in the ASP.NET[^] forum.
|
|
|
|
|
Hi all,
I am doing a very simple operation via c#.
1 I just copy an existing JPEG file in temp directory.
2 Then I open the copied Jpeg file from temp directory.
3 I try to delete the original Jpeg file and application crashes.
Please see below c# function for this:
using System.IO;
public void DeleteAfterCopyingOriginalImageFile(string strOriginalJpeg)
{
string strTempFolder = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "JpegTemp");
if (!Directory.Exists(strTempFolder))
{
DirectoryInfo directory = Directory.CreateDirectory(strTempFolder);
directory.Attributes = directory.Attributes | FileAttributes.Hidden;
}
string strTempJpeg = System.IO.Path.Combine(strTempFolder, "TempImage.jpg");
if (!File.Exists(strTempJpeg))
{
File.Copy(strOriginalJpeg, strTempJpeg);
}
Process.Start(strTempJpeg);
File.Delete(strOriginalJpeg);
}
I need to follow exactly these steps (cannot delete original file before opening TempImage.jpg). Can anybody help in knowing why copy and opening of temp file lock the original file. How can I prevent original jpeg file from being locked. I am new in .Net. Please help me.
More Info about the user case: The user case is that user cannot perform any operation on original file. So a temporary copy of original file is created in temp folder. User can then open/edit temp file. And if he thinks that he can replace original file with that of edited (copied in temp directory) one or he does not need original file any more, he can delete original file (and if required, can make temp file as the original one). So I strictly need to follow the same steps.
Regards
Aseem
Thanks in Advance
|
|
|
|
|
DO NOT cross post or repost you question.
You have received responses to your original post. Posting again will not allow others to see all the context and what has been tried already.
Read "How to get answers..." at the top of this forum!
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
|
You can't. THe image is represented in memory as a 32-bit full resolution bitmap in memory. In the file, it's compressed down to whatever the JPEG encoding settings are. For example, an image that is 3000x2000 pixels will take up 24MB of memory at full resolution. The resulting image on screen will not be that large, so it'll get painted scaled down to whatever size is visible. There is no class in the .NET Framework that will reduce the memory size by representing the image in its file format. You'd have to either write your own class to do this or find a 3rd party library that does this. I don't know of any.
|
|
|
|
|
if, I repeat: if, your PictureBox is significantly smaller than the original image, then you could solve your problem by creating a new and smaller image, like so:
Bitmap bm1=Bitmap.FromFile(filespec);
Bitmap bm2=new Bitmap(bm1, myPictureBox.Size);
bm1.Dispose();
myPictureBox.Image=bm2;
if not, there's nothing much you can do about it, as .NET keeps images in RAM as real bitmaps (normally 4B/px).
|
|
|
|
|
|
Probably because it implemented a custom class to represent the image in its native file format in memory. That would also mean it has to have custom rendering code to parse the image data, as needed, and only the sections of it that are required to render the visible part of the image on screen.
|
|
|
|
|
Hi,
Hope this is the right place to post this question. If not please let me know the right place.
I've an application in .net 3.5 framework. I would like to create a setup for the application, which will install the .net framework also(if it doesn't present in client machine). Please guide me how to achieve this. Thanks in advance.
|
|
|
|
|
YOu can use VS to create a setup program. It will automatically detect dependencies such as the .NET Framework and offers an option to include it with the setup or download it.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Thanks for your reply. I created setup project for the application and it detected .Net framework dependency automatically. But could you let me know where can I find the option to include framework so that it will install framework while installing the application. Thanks in advance
|
|
|
|
|
View the properties for the setup project then click the Prerequisites button
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
|
Navigate the given link to know how to deploy application along with .Net Framework
deployment guides[^] and click on this Link[^] to download The guide provides information on deploying all types of Framework application using a variety of mechanisms, including no-touch deployment, and Windows Installer package deployment.
Hope it will work for you.
|
|
|
|
|
MEMSG.To = GetData(tsqlemail)
the ERROR i get is: Property 'To' is 'ReadOnly'.
how do i correct this???
deepshikha
|
|
|
|
|
Hi,
which type is MEMSG from? Maybe there is a static method for the MEMSG-type to pass "To" to.
Regards
Sebastian
|
|
|
|
|
This means that there is no public setter for the To property. There will be another mechanism for adding the data, maybe via the constructor - unfortunately, without the 1000 mile telepathic link available, I have no idea what MEMSG is so can't tell you what this mechanism is.
|
|
|
|