|
I read this, because in the MSDN is noted that the AutoResetEvent handles that threads can give signalys to each other.
I hope i can interpret this sample code right:
First of all you defined a AutoResetEvent-object and an int named count.
It begins in the Main-Thread: First there is a if-call, whether a parameter was taken over at a call of the Test.cs. (This count says how often the EnumWindowsCallback-method will be executed?)
Then the AutoResetEvent evt is initialized and set to false - this means that the Event does not give up a signal to an other thread.
Then a new Timer-Object is initialized and in the course of this initialization the delegate-method will be called. (why don't you hand over the evt-object in the constructor of the Timer-object?)
What value has the TimerCallback-paramter in the constructor of the TimerCallback?
Then when the Timer-object is initialized and the TimerCallback-method is called, the today's date is write out on the console.
Then the EnumWindows-method is called. In the course of that the EnumWindowsCallback-method is called. (What values have the parameter of the EnumWindows-method?)
Within the EnumWindowsCallback-method there is a if-call - apperantly, if there are any windows open? - then the method GEtWindowText asks if the window has a title - if true the title will be write out on the console. (what means the nWnd.ToInt64() and the 0x{0:x8)?)
You see the course and order of events are still not clear for me...
I'm already afraid to ask you again for help..
yours sincerely,
patrick
|
|
|
|
|
pat270881 wrote:
why don't you hand over the evt-object in the constructor of the Timer-object?
And marshal it across thread boundaries for no reason? That's inefficient and unecessary. Just because the .NET Framework makes some things so easy does't mean you should do it that way. And passing a value type (like count ) as an object requires boxing and unboxing, which is very expensive (in terms of CPU time). Even casting reference types takes extra cycles that aren't necessary by keeping it as a field.
pat270881 wrote:
What value has the TimerCallback-paramter in the constructor of the TimerCallback?
It's the method that the delegate references. As I said before, a delegate is like a managed function pointer.
pat270881 wrote:
What values have the parameter of the EnumWindows-method?
It's in the Platform SDK for EnumWindows .
pat270881 wrote:
what means the nWnd.ToInt64() and the 0x{0:x8)?
It's in the .NET Framework SDK. Look-up IntPtr.ToInt64 and string formatting. There's no purpose explaining this if you haven't even read about it yet. If you have questions beyond that, this is the place to ask.
As far as the flow of execution you are right. The code is pretty self-explanitory if you understand the types and members used in the code.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
hello,
yes i will look for this in the SDK.
But my biggest problem i still have is the Delegate-Callback mechanism? I do not simply understand how this mechanism functions, respectively in your sample code.
I read the things to delegates and TimerCallback in the MSDN and looked at the samples but i did not understand how this exactly goes?
That is for sure still my biggest problem... I do not find the logic in this mechanism..i hope i express me the right way...
yours sincerely,
patrick
|
|
|
|
|
As I've said several times, a delegate is a managed function pointer. This allows you to pass a method as a parameter and execute it without knowledge of the actual method that needs to be executed. Just like with the EnumWindows API - in native code you pass a function pointer. In .NET, you pass a delegate (a function pointer managed by the CLR). See the Delegate class in the .NET Framework SDK for more details.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
yes i know defintion of the delegate, but the thoughts behind why you build up this sample in that way is not clear.
You have explicit the EnumWindowsProc-delegate but you have not explicit declare the TimerCallback-delegate?
And why do we need the evt.WaitOne(); after the creation of the Timer-object? - the AutoResetEvent evt is already set to false.
yours sincerely,
patrick
|
|
|
|
|
The TimerCallback is a delegate that's already declared in the .NET Framework and the .NET CF. Why would I declare it? You don't re-declare the TimerCallback , you instantiate it with reference to a method that you must define. That's a delegate.
Why do I call AutoResetEvent.WaitOne ? Because the Main method has to block until signalled otherwise the application will terminate immediately since the Timer was started on a different thread. That certainly is not what you want.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
okay that's clear.
You said the main-method and the TimerCallback-method run in different threads. How is it distinguished that the TimerCallback runs in a different thread? - when it would not run in a different thread i wouldn't need the evt.WaitOne()? - because the execution of the class goes only forward when the TimerCallback-method runs through and calls the EnumWindowsCallback and so on?
yours sincerely,
patrick
|
|
|
|
|
...and do you know any further method besides the record of the titles of the open windows that i can log to get more detailed information about what do user do or which commands he executes?
Thanks in advance.
Yours sincerely,
patrick
|
|
|
|
|
hello,
i have now a little application which writes the title of the active window in a xml-file, but when i want to deploy it with the Emulator there will occur the following exception and i do simply not know why this error occurs??
A managed MissingMethodException
occured at
Test:TimerCallback+0x25
Test:TimerCallback+0x25
Timer:ring+0x59
Ok to terminate.
Can somebody please tell me what went wrong?
thanks in advance.
regards
patrick
|
|
|
|
|
I looked in the MSDN for some helpful topics but i only found "An Introduction to P/Invoke and Marshaling on the Microsoft .NET Compact Framework". I do not know, if this topic helps me..but i don't think so.
Without any example code it is very difficult for me to realize your idea with the EnumWindows, Timer-Class, etc, because i do not work yet with this classes (EnumWindows,etc.), regardless of array lists and hashtables.
Have you got further tipps or hints?
thanks in advance.
yours sincerely,
patrick
|
|
|
|
|
If you look at the code I gave, I already showed you how to P/Invoke EnumWindows and how to declare the EnumWindowsProc delegate (what you name it doesn't matter, though). For the various Timer classes, look in the .NET Framework SDK (it's installed locally if you took the default installation for VS.NET: just type "Timer class" in the index and check to make sure at the bottom of the page that they support the .NET CF). They should all have examples of use.
Being given the answer won't teach you everything. The hardest part of this solution is the P/Invoke, which I already gave you code for earlier.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
hello,
i have some problems with the NSpring Framework. I want to use this framework to log in a file, which events occurs in a ASP.NET Application. But i do not really know how i can use this framework and how to start with it.
The situation is as follows: i developed a ASP.NET Application for a PDA and now i want to change the code in that way that it would be logged in a file on the PDA what actions a user execute (which events would be execute, which method, at what time,..).
Can anybody help me with this problem?
thanks in advance.
yours sincerely
patrick
A Comprehensive Logging Package for .NET
|
|
|
|
|
If you have specific problems with an application/library, you should ask the authors and/or their support contacts. Since NSpring is hosted on SourceForge, there are a couple differnet forums you can use.
If you have questions specific to C#, this is the place to ask.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
hello,
oh i thought i can post it here because the framework is also explained on this site. on the www.SourceForge.net page i didn't find a forum where i can post my question??
yours sincerely
patrick
|
|
|
|
|
No, the ".NET Framework" is discussed on this site, not the "NSpring Framework". Specifically, this forum is for discussions about C#, one of many languages that target the CLR (part of the .NET Framework).
If there is an article you found on this site that discusses NSpring, then you should ask this question on that articles message board at the bottom of the page; that's what it's there for.
If you go to the SourceForge project page and look, you'll see a Support[^] link.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
|
hello,
i already post my question on the forum of jeff, but he did not answer.
yours sincerely
patrick
|
|
|
|
|
i am using a lot of bitmap objects in my application , when i get to over a 100 objects with bitmaps my application slows and eventualy crashes, how can i handle the memory problem ? is there a better way to save images than with bitmaps?
|
|
|
|
|
blankg wrote:
is there a better way to save images than with bitmaps?
When you are done with the Bitmap call Dispose() . Another option is to use the C# using keyword so that appropriate try/finally blocks are emmited and then your Bitmap object will be cast to an IDisposable and Dispose() will be called automagically for you.
using (Bitmap b = new Bitmap("C:\..."))
{
}
- Nick Parker My Blog | My Articles
|
|
|
|
|
For any object that implements IDisposable , you should always dispose of the object when finished. This includes (and definitely is not limited to) Bitmap and Graphics . In C#, you can use the using statement to make sure that objects are disposed even in case an exception is thrown:
using (Bitmap bmp = new Bitmap(32, 32))
{
using (Graphics g = Graphics.FromImage(bmp))
{
}
bmp.Save(...);
} This ensures that unmanaged resource (resources that aren't managed by the CLR, like native handles) are freed and that managed objects are disposed of immediately instead of the next time the GC (garbage collector) is run by the CLR.
On a note, if you call Environment.Exit finalizers (like destructors in C++...sort of) are executed but IDisposable.Dispose is not. This really isn't too important since Environment.Exit will unload the CLR and exit the host process - the OS will free all handles in use at this time. If any exceptions are thrown or you return execution to the caller, using the using statement will still dispose the object. The following is equivalent:
using (Bitmap bmp = new Bitmap(32, 32))
{
}
Bitmap bmp = new Bitmap(32, 32);
try
{
}
finally
{
bmp.Dispose();
}
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
hi all ,
As part of my preparation for an upcoming presentation on .NET reflection API
at the next Cochin .NET user group meeting , i have created a small four function
calculator [ + , - , / , * , ( . ) , unary + , unary - , numbers ] which can evaluate
arbitary mathematical expressions.
Aim of the code is just to show how one can use Reflection.Emit code to
create an assembly on the fly.
u may download a zipped PDF file from the following url
http://www.praseedpai.com/Misc/misc.html
I hope this will give an overview to a novice developer on IL code generation
Here is how u can use the code
----------------------------------------
Copy the contents of the PDF document on to a text file ( Expr.cs ).
use C# command line compiler csc to compile the code as follows
csc Expr.cs
u may execute the program like this
Expr "2*3"
Expr "-2+3*4"
Praseed Pai
P.S :- All the numbers are treated as doubles . No decimal points are allowed in
numbers .
|
|
|
|
|
I would suggest that you write up an article covering the material in your presentation. There are too many questions that get asked in this forum, your thread will quickly disappear.
- Nick Parker My Blog | My Articles
|
|
|
|
|
Hi,
I've designed 2 custom controls (ColorButton & ColorRadioButton) that subclass off the original windows controls, but are composed of 3 images each (left cap, right cap, center slice). I need to build a set of subclasses of these buttons (ie OrangeButton,
GreenButton,...) which are identical to the parent except the bitmaps (which I have set up as properties) would be distinct. This works fine, but I don't want my base classes (ie ColorButton) to be visible in the Design view (from the toolbox). I tried making the base class protected, but that won't compile. How can I restrict one class in a dll from the toolbox while allowing the derived classes to show up?
thanks!
Deanna
|
|
|
|
|
there is an attribute you can apply to your components that will prevent it from being able to show and select into the toolbox, what it is called i cannot remember look in system.componentmold.design perhaps.
top secret xacc-ide 0.0.1
|
|
|
|
|
Actually, there are a few and they are in the System.ComponentModel namespace.
Those are BrowsableAttribute , EditorBrowsableAttribute , DesignTimeVisibleAttribute , and DesignerSerializationAttribute (a little less like the others, but can hide the code from the code serializer).
I'm not sure if these will help, though. Customizing the toolbox in VS.NET reflects the .NET assembly you opened and looks for Control derivatives. Whether or not that code makes use of the attributes mentioned above is questionable (only giving it a try would determine such behavior).
Another attribute that may work (though I've never used it) is the ToolboxItemFilterAttribute . This would at least make the toolbox item hidden if the filter string was specified to never match anything. I doubt this would prevent the control from showing up in the toolbox customization dialog, though.
Microsoft MVP, Visual C#
My Articles
|
|
|
|