|
You want entertainment…… well you got it! :
I have a C# application that invokes COM objects. I need to stop a COM instance from executing when it executes more than a predefined amount of time. Each COM instance is assigned a thread.
System.Thread.Abort() does not achieve that result because when calling Abort() on a thread, if the thread is currently executing native code (or COM in my case), nothing will happen until the thread returns to managed code. To solve the problem I thought with the help of the forum of these solutions:
1. Creating an exe (Process) that invokes the COM and assign a thread to a function that launches that exe. When a thread aborts, I will kill the exe and stop the COM execution. This approach has worked.
2. Create a MTA COM component that spawns a native thread and the COM object with methods added to the abort the Native threads.
3. Instead of using Managed Threads, I can P/Invoke Native threads by using the CreateThread/ExitThread/TerminateThread API. Aborting threads occurs in a rare occasion.
I appreciate any useful comment.
|
|
|
|
|
If anyone is interested ,delegates are used instead of addressof.
|
|
|
|
|
Well, it took me looking into your message histroy to see what's you're really trying to do here. Launching multiple instances of VB6-created .DLL, COM based. Hmmmm....interesting since VB6 runtime doesn't support threading, directly anyway.
Creating a seperate .EXE will work, since each launch of the .EXE will, of course, spawn on it's own thread. This will also make any communication with the instance of the .DLL a huge PITA, since now your crossing a Process boundry. I hope this .DLL doesn't do anything useful to the form.
In my opinion, option number 2 is your best bet. Keep manangement of the unmanaged threads in a COM-based component that exposes any interface your .NET app can use to control the launching and shutdown of the VB6 component instances. This COM component can also handle communication to and from the VB6 stuff for your Managed code to.
Why do I say this? Because in your original post, that you didn't tell us anything about, it sounds like this VB6 component could be replaced sometime in the future. By creating a wrapper for the VB6 threads, you can easily replace this interface component with a different interface when the VB6 component is finally replaced by managed code.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I needed a quick answer to a quick question!
I am working on Options 2 and 3(Option1 is done) in parallel since they hold the same complexity which is mainly working with unmanaged threads.In both cases i am creating a wrapper to the COM either with creating COM-based component or a .net assembly or class( never figured it out yet).The problem i am facing is how to stop a thread execution.TerminateThread is not the answer(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/terminatethread.asp[^]), how to gently terminate a thread keeping in mind that the COM source code cannot be changed.Any code can only be added to the Wrapper.
|
|
|
|
|
You don't have a choice here. Either your VB6 code was written to terminate itself property on some flag, or you'll have to forcefully kill it, which will lead to memory and handle leaks.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Thanks man i appreciate it..
|
|
|
|
|
Thanks Dave i appreciate it..
|
|
|
|
|
I have a very superficial understanding of programming in Windows, and am merely trying to solve a simple problem for a friend.
Basically, I want to simulate the keystroke "VK_MEDIA_PLAY_PAUSE" allowing programs such as Winamp and/or WMP to detect and respond, in the exact same way they would if I physically pressed the key.
I've been experimenting with HWND_BROADCAST and SendMessage, but don't really understand how they work -- any insights?
|
|
|
|
|
SendMessage is used to send Windows messages to a specific window, given the handle of a window. When used with HWND_BROADCAST as the window handle, it sends the message to every window in the system. So if Winamp and Media Player are running, they would get the message too.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Hi to all. I am trying to provide a help file for the project I am developing. I have the test.hlp file but I have no idea how to open this file when the user click on a button. Is there any way to do this?
Thanks in advance.
|
|
|
|
|
|
Hello everyone, I'm back again...
I'm working on some printing dialog with integrated preview. The problem is how to determine corrent font size (height) for the preview.
Of course, the preview image size is measured in pixels, so for the A4 you have e.g 176x140 px large image. When I want to draw something on it with font of user-defined size in px, the preview size must be some N-times smaller. The key problem is how to get the N.
Images are printed correctly, because I can convert its sizes in some useful units, like inches or percents, so they can be drawn with knowledge of document size in hundreths-per-inch units correctly.
But with fonts, I can use only some Font.GetHeight(...) method, which returns (for my printer resolution) value of 186.8591 (inches or what ?) for the 10px font.
|
|
|
|
|
Specify the font size in points instead of pixels. One point is 1/72 of an inch.
---
b { font-weight: normal; }
|
|
|
|
|
You can use the Graphics.MeasureString( ... ) function to get the pixel height of a Font 's output.
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
Hello gurus,
I'd like to know how to generate a GUID in C#? Can somebody show me a code snipet please?
Best regards.
Thanks.
Fred.
There is no spoon.
|
|
|
|
|
Easiest way:
textBox1.Text = Guid.NewGuid().ToString();
|
|
|
|
|
as simple as this
thanks
There is no spoon.
|
|
|
|
|
Damn, C# has everything onboard. Can it also wash my dirty clothes?
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Yes, of course.
Create a WashingDay object using the System.Globalization.Calendar class. Then you add any cloth items to it's Items collection. Remember to associate each item with a WashingType object first, though, or you will end up with pink shirts. When you added all the clothes, subscribe to the OnComplete event and execute the WashingDay.Start method.
---
b { font-weight: normal; }
|
|
|
|
|
|
My C# Express IDE suddenly(?) doesn't let meswithc betweenn debug and release anymore.
Currently it builds the library project as release, and the test env as debug. Weird (but maybe poking aorund I changed it).
"Solution Configuration" is disabled, hunting the menus (or customizing the toolbar) doesn't reveal anything.
I already tried resetting the IDE config, but this didn't help
Any suggestions?
We say "get a life" to each other, disappointed or jokingly. What we forget, though, is that this is possibly the most destructive advice you can give to a geek.
boost your code || Fold With Us! || sighist
|
|
|
|
|
Had the same problem. THe following steps should work.
1. Go to Tools->Options and check the "Show All Settings" at the bottom of the dialog
2. Expand Projects/Solutions, click on General and check the "Show advanced build configurations" checkbox".
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
thanks! that worked!
We say "get a life" to each other, disappointed or jokingly. What we forget, though, is that this is possibly the most destructive advice you can give to a geek.
boost your code || Fold With Us! || sighist
|
|
|
|
|
I found (without finding that checkbox mentioned below) that it would build the debug when you try to run it thru the debugger, and it would build the release if you clicked on "build solution" in the build toolbar.
|
|
|
|
|
Hi i made a Modal DIalog Box( showdialog() )
Its on top and everything, but the application who calls it( another enviroment ) steals back the focus, but with my modal dialog box on top still. This annoys me! meaning i cannot just press enter to move along, but need to get focus back to my dialog form, before i press enter.
How can i make sure that it(dialogbox) always have focus over other applications, that nothing takes it away.
is there some windows api i can call or something, i have been looking but with no luck.
Thx in advance
|
|
|
|