|
You can get the size using SHGetFileInfo but I don't think it can be set. There's a registry setting that applies to some versions of windows but not all (not vista for example).
Dave
|
|
|
|
|
I am writing a code to test a COM object and one of its functions has an infinite loop.
Basically my code should run this COM object function in a different thread, give it some time to finish but if it doesn't, terminate it.
However, I encountered the following problems:
1) Thread.Abort wouldn't abort the thread because you can't use .NET Thread.Abort to abort unmanaged code.
2) AppDomain.Unload wouldn't do anything because it tries to abort all the threads.
3) I tried using Marashal.ReleaseComObject and it resulted with:
"An attempt has been made to free an RCW that is in use. The RCW is in use on the active thread or another thread. Attempting to free an in-use RCW can cause corruption or data loss."
By now the only current options I see is either using somehow the original Windows API to abort the thread or create a process especially to test the function. Both methods seem like a lot of overkill for what I'm trying to do.
Anyone has any ideas?
Vitaly Belman
|
|
|
|
|
One idea: Write an unmanaged wrapper around the COM object that will stop it and return an error code if it times out. So a call to this wrapped object will always return.
Another idea: Get the source to the COM object, fix the infinite loop, and recompile it.
Another idea: Characterize the cases that result in an infinite loop, and avoid calling the function when this would happen. (I like this idea best.)
|
|
|
|
|
Alan is right there, I'm afraid. There's just no way. You simply cannot kill a thread which is stuck in an unmanaged call. We had this problem too with DCOM calls not guaranteed to return, and had to learn that there is no way to get rid of the calling thread but to kill the process. Calling windows api to abort the thread is out of the question when you have a managed thread cause it will pull the api thread right away from under your managed thread's arse and lead to whatever results. So either you set up a complete process for testing, or you handle the testing within COM (but not in VB6, for lack of threading capabilities, but in C++ with ATL and all that void** stuff).
I don't envy you, if that's any consolation. As Alan said, the best bet would be to avoid all situations where the COM call can hang.
|
|
|
|
|
Hi there,
I have a simple user control that I would like to handle mouse events for (such as mouse down etc.). My user control has a couple of Panel objects on it, and these are receiving the mouse events I am interested in. I would like the parent user control to handle the events instead of the panel objects (or anything I insert onto the parent). I understand that I can assign the panel (and any other child object's) mouse event handlers to be the event handler I wrote for the parent, and that works as desired, but I'm wondering if there is a better solution?
So my question is: to have mouse events handled by a parent object, do I need to have each child object's event handler set to be the parent handler code, or is there a property I can set to automatically pass the event to the parent?
Many thanks.
- Dy
|
|
|
|
|
Hi,
I would try setting Control.Enabled=false; for those Controls that should not
react on keyboard and mouse. This would influence the rendering for some, not for Panel AFAIK.
|
|
|
|
|
That technique works well, thank you Luc.
As you said, it influences some controls paint jobs. Whilst that doesn't affect the control I'm working on at the moment, it probably will in the future, so I will continue to look for another means too.
- Dy
|
|
|
|
|
I've had this problem too when the question came up whether a control could give users a possibility to drag child controls around. Either you don't use controls at all and do everything in the OnPaint method (which is pure hell), or you have to suscribe to the mouse events of all child controls. So far I haven't come up with anything better than a central ChildControl_MouseDown handler and a call in the constructor (after InitializeComponent) like foreach (control in this Controls) control.MouseDown+=ChildControl_MouseDown
|
|
|
|
|
Hi,
I'm working to convert some java code to C#. I'm struggling to determine what is the equivalent C# statement to the Java "UnknownHostException". Can anyone point me in the right direction?
Regards,
Dave
|
|
|
|
|
As far as I know, there isn't an equivalent exception. If you need an exception of this specific type, you will need to derive it yourself from ApplicationException.
Scott Dorman Microsoft® MVP - Visual C# | MCPD
President - Tampa Bay IASA
[ Blog][ Articles][ Forum Guidelines] Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
|
|
|
|
|
just use ApplicationException as you are just advised
Vuyiswa Maseko,
Sorrow is Better than Laughter, it may Sadden your Face, but It sharpens your Understanding
VB.NET/SQL7/2000/2005
http://vuyiswamb.007ihost.com
http://Ecadre.007ihost.com
vuyiswam@tshwane.gov.za
|
|
|
|
|
I want to process something when keys.control and keys.left are pressed at the same time,so how do i know if them are pressed at the same time? Thanks!(C#)
|
|
|
|
|
Detect when the control key is pressed and released and store the status in a variable, so that when the left key gets pressed you can check if the control key is currently pressed.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Thanks for you reply!
I have solve my question.
code:
//Onkeydown
if(e.KeysData.tostring().contains("Control")&&(e.Keysdata.tostring().contains("Left"))
{
// do my work;
}
But i found a erratic thing:
if i press keys.left or Right/up/down,it ignore me in function OnKeyDown,OnKeyUp,OnKeyPress;
if i press keys.control and keys.left,it will process my work;
if i press keys.shift and keys.left,it will ignore me in function OnKeyDown,but process in OnkeyUp;
.....
i want to know when will those events occur?Could you help me?
|
|
|
|
|
Hi,
you can get the instantaneous value of the modifier keys using Control.ModifierKeys
so you don't have to track those keys yourself (which you can hardly do correct, say e.g.
the CTRL key gets pushed down on one Control, then released above another Form).
BTW: don't convert to string for a logical test; instead of
if(e.KeysData.tostring().contains("Control"))...
you can do:
if ((e.KeysData & Keys.Control)==Keys.Control)...
or
if ((e.KeysData & Keys.Control)!=0)...
|
|
|
|
|
Hi All,
I'm just looking at my class that builds a dynamic filter to be apply to a DataView. Originally the potential input to this class was predefined a ComboBox for this field, one for this field etc ...
However, I'm now looking at adding in some more complexity which may include an unknown number of certain ComboBoxes for a particular field. This is obviously adding in a lot of complexity to building the required filter string.
Is there a design pattern for this that I should be reading up on to make this class extendible and very dynamic??
Thanks in advance,
Jammer
Going where everyone here has gone before!
My Blog
|
|
|
|
|
Hi I was wondering how can I select specific row in dataGrid.
I want that if textbox (value) matches with sepcific cell in datagrid than i want to select this row.
Can you help me ?
|
|
|
|
|
if("dd"==DataGrid.items(i).cells(j).text)
so what you want may be:
DataGrid.items(i).cells(j).RowNumber(this is the row index in the control)
|
|
|
|
|
See the Following Article
http://www.codeproject.com/KB/cs/N-Tier22.aspx[^]
Hope it helps
Vuyiswa Maseko,
Sorrow is Better than Laughter, it may Sadden your Face, but It sharpens your Understanding
VB.NET/SQL7/2000/2005
http://vuyiswamb.007ihost.com
http://Ecadre.007ihost.com
vuyiswam@tshwane.gov.za
|
|
|
|
|
hi,
what is the advantages of switch over the if/else ?
where we prefer the if/else over the switch?
|
|
|
|
|
Switches are generally easer to read for a large number of conditions or a set of conditions that could possibly change over the lifetime of the product. If/else is great when you have a small (2-3, in my opinion) number of conditions.
That being said, there are times when you still have to use an if/else (or if/else if/else) block with a large number of conditions as switches only let you switch on a limited set of data types.
Scott Dorman Microsoft® MVP - Visual C# | MCPD
President - Tampa Bay IASA
[ Blog][ Articles][ Forum Guidelines] Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
|
|
|
|
|
In addition to the above, with some data, a switch statement will resolve into a simple jump table. A switch statement with strings may end up using a hash table, increasing performance.
Even for simple compares, I tend to use if/else if the number of elements is one or two items.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
Anywhere you compare the same expression to several values, you can use a switch instead.
If you have a lot of comparisons, a switch usually gives clearer code, and may perform a bit better. If you only have two-three comparisons, it's mostly a matter of taste. Use whatever best fits the intention of the code.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Guffa wrote: Anywhere you compare the same expression to several values, you can use a switch instead.
As long as they are simple integers, or strings; and literal!
|
|
|
|
|
If you have a very large number of possible values to test for, you can order nested if/else structures to simulate a binary search.
For the innermost loop of time-critical code, this can run faster than a switch that tests each value sequentially.
For example if value is between 0 and 7:
if (value < 4)
if (value < 2)
if (value == 0)
else
else
if (value == 2)
else
else
This will find the value in three steps, as opposed to up to seven steps using a sequential method.
|
|
|
|