|
HI Everyone!
I have used this line in AfterSelect Event of treeView.
e.Node.IsSelected && e.Button == MouseButtons.Right
But this doesn't recognize "e.Button"
Is there any NodeMouse_Click event? How can I use that?
I want to invoke context (popup) menu in tree that enable and disable its item according to selected node. But when i click using rightMouseButton the treeView node not considered as selected.
please tell me how i can select node using right mousebutton.
Thank you.
|
|
|
|
|
If you want to get the mouse button that's currently down, you can access that by the static Controls.MouseButtons property.
|
|
|
|
|
We are using a COM library through interop (ESRI's lib). Since the library is sometimes slow we decided to create a dialog to allow the user to cancel a long running request.
The request is running on a thread. Pressing the cancel button on that dialog will Thread.Abort() the request.
The problem we are facing is that the application's behavior is unpredictable after the user performs several cancellations. Sometimes, the application waits forever (hangs) and sometimes it just takes all of the processor's time.
As you can see there is little info here. The only thing that we know about the COM library is that it is running in a single threaded apartment - STA.
Questions:
1. Is it possible to do this kind of threading work with an STA COM library through interop?
2. Is there any other way to do the same thing (other than aborting the thread)?
3. Do you have any experience with multi-threading ESRI tasks in .NET (not C++)? If yes, can you please provide any advice on how to tackle this problem.
We posted this problem on ESRI's forums to no avail
Any help is greatly appreciated.
Thanks
|
|
|
|
|
This really sounds like a problem with the vendor's dll.
Now, aborting threads is generally a bad idea; it's better to manually cancel by building the work to watch for a cancellation flag so that it can do the necessary cleanup. Without cleanup, as you've discovered, code is left in an unpredictable, volatile state.
Emad, what happens if you run the work on a background thread? Then if the user cancels, would it be safe to leave the work running, but the user doesn't see the work running? If that's feasible, that may be your only option outside of having ESRI provide some cancellable work method.
|
|
|
|
|
hi Judah,
yes it seems like it is a problem with the vendor's library.
I am not sure about the cancel flag. We are working with Legacy code that we need to wrap the cancellation code around (not new design). Also, having code littered with checks like (if cancelled) doesn't seem to be the best solution for us.
We are running the work on a background thread as you suggested. Leaving the work to run sounds like a good idea. It is worth a try if all fails.
Thanks for your help.
|
|
|
|
|
Hi,
Before generics I used something like this to connect childs with parent classes
interface IMyItem
{
CollectionOwner Owner{get;set;}
}
class MyCollection : System.Collections.CollectionBase
{
public MyCollection(CollectionOwner owner)
{
_owner = owner;
}
protected override OnAdd(object item)
{
if(item is IMyItem) ((IMyItem)item).Owner = _owner;
}
}
this way one was able to add items to a owner class owner.Items.Add(new Item()) and the owner had the item instance in his list while the item had a reference to his owner, which made a call like item.Remove() possible instead of calling owner.Items.Remove(item)
Now, .net 2.0 introduced generics, way cool. But how do I implement this behaviour with generics? There is no overrideable method instead of using the brute force method with new
class MyCollection<T> : List<T>
where T : IMyItem
{
MyCollection(CollectionOwner owner)
{
_owner = owner;
}
new public void Add(T item)
{
item.Owner = _owner;
base.Add(item);
}
}
this way if one is casting MyCollection back to List<> my custom add method isn't run. bad design
how can I extend generic collection base classes with such logic to do some extra work on each add or remove?
myMsg.BehindDaKeys = "Chris Richner";
|
|
|
|
|
Rather from inheriting from List<T>, have your class implement IList<T>, and keep a List<T> field in your class. Something like this:
public class MyCollection<T> : IList<T>
{
readonly List<T> list = new List<T>();
public void Add(T item)
{
item.Owner = _owner;
list.Add(item);
}
....
}
Of course, for you to set the Owner property of the item, there must be a constraint on your T class type. You could accomplish this like this:
interface IOwnable
{
CollectionOwner Owner { get; set; }
}
The tell your MyCollection object that only IOwnable objects can be stored in it.
class MyCollection<T> : IList<T>
where T : IOwnable
{
...
}
*edit* alternately, as Daniel said, inheriting from the System.Collections.ObjectModel.Collections would require less work. You'll still need the IOwnable constraint if you want to set the owner on the items.
|
|
|
|
|
Instead of inheriting from List<t>, inherit from System.Collections.ObjectModel.Collection<t>. There you can override ClearItems, RemoveItem and InsertItem, which will be called by all normal Add/Clear/Insert/Remove/RemoveAt methods.
|
|
|
|
|
Thanks guys,
This way round things look like they did in System.Collections.xx namespace. Seems like I just got the wrong base class ;(
myMsg.BehindDaKeys = "Chris Richner";
|
|
|
|
|
Hello
I am using SendAsync command on the Smtp client to send the email message. Although, it seems that the message was send, it does not get send until I close the form. How can I make, so that the message goes out right away?
Thank you.
|
|
|
|
|
If you're using the MailMessage class, try calling the Dispose method.
|
|
|
|
|
Is there a way to get the default namespace name?
If I embed a resource in a dll file the resource will be named <default namespace="">.<file name="">.
But I don't want to hardcode the default namespace name into the code (because I may change later and forget to change in code the namespace).
Any suggestion is welcome
|
|
|
|
|
|
I need to find out the default namespace that we set using the Project Property page -> Default Namespace.
I know how to get the executing assembly or calling assembly's namespace.
|
|
|
|
|
The default namespace is not stored in the compiled assembly, so you cannot do that. If you have a class that's in the default namespace, just use typeof(ClassInDefaultNamespace).Namespace.
|
|
|
|
|
Daniel Grunwald wrote: The default namespace is not stored in the compiled assembly, so you cannot do that
Thanks, just as I thought.
Strange however that the ResourceManager uses the default namespace to prefix the embedded resource file name.
|
|
|
|
|
Using C# does anyone know how to convert a number to the power notation, so that it can be displayed at runtime and also pinted in power notation.
Andreas
|
|
|
|
|
What do you mean exactly, can you give an example?
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Do you mean something like this:
String.Format("{0 .###E+000}",Convert.ToDouble("01234567890"));
|
|
|
|
|
Hi,
In regards to updating the database with the data in a dataset, I currently loop through the records in the dataset and get the state of each row and then call the necessary stored procedures to do the delete or update or insert into the database.
Recently I read that the same thing can be simplified by using the dataAdapter.Update()
This seems to be an easier way since I do not have to do the loop on each dataset record and get the state of it...
What do you think please?
Thanks
|
|
|
|
|
|
DataAdapters are also especially useful if used in conjunction with databinding. A lot of the manual loading/saving/assigning/datatable modification that might be necessary is done for you.
If you're using VS.NET2005, check out the msdn pages on the DataAdapter class and the BindingSource class, and check out the CP articles on databinding, it really does save a lot of your time.
|
|
|
|
|
I've created an application that sends images along with some other information in an XML message from a handheld device to a server running on my pc. There are 14 records in the database I'm processing on the handheld, and the first four images and information come up just fine. Then things start to go wrong. As far as I can see in my log file, everything is overrwriting, my logfile stops making sense and new lines seem to be everywhere.
Basically, I have a class for creating my XML message, with the AddImage method as below;
<br />
public bool AddImage( string tagname, string ImageFile )<br />
{<br />
bool Result = false;<br />
<br />
try<br />
{<br />
FileInfo ImageInfo = new FileInfo( ImageFile );<br />
<br />
int ImageSize = Convert.ToInt32( ImageInfo.Length);<br />
<br />
using (FileStream SaveImage = new FileStream( ImageFile, FileMode.Open, FileAccess.Read, FileShare.None ))<br />
{<br />
byte[] ImageData = new byte[ImageSize];<br />
int BytesRead = SaveImage.Read( ImageData, 0, ImageSize );<br />
<br />
xmlMessagePacket.Append( "<" + tagname + ">" + Convert.ToBase64String( ImageData, 0, BytesRead) + "</" + tagname + ">" ); <br />
}<br />
<br />
Result = true;<br />
}<br />
catch (Exception gExc)<br />
{<br />
errorState = gExc.Message + " / " + gExc.StackTrace;<br />
}<br />
<br />
return Result;<br />
}<br />
I add the fields in, and the first four messages work fine, but after that the application hangs.
Can anybody suggest what I should look at first? Could it be that I'm overloading my socket somehow.
|
|
|
|
|
|
Thanks for that, but I'm not entirely certain that is the problem. Basically, when I send a message, I set a loop going;
while(!MessageReturned)
Application.DoEvents( );
so I can't send the next message until my event fires with the return of my previous message. According to my logfiles, the application thinks it is able to send several more messages after the one that causes it to fail.
Very confusing.
|
|
|
|