|
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.
|
|
|
|
|
hammerstein05 wrote: Could it be that I'm overloading my socket somehow
I don't even know what that is supposed to mean but I doubt that is the problem. Based on what you posted it is far more likely that you have a bug in your protocol and/or implementation of the protocol.
led mike
|
|
|
|
|
Does the apparent lack of a closing tag in your XML message make any difference in how the code behaves? That's the only obvious thing I can spot.
Have you run the code in a debugger to see where exactly the code is hanging up?
|
|
|
|
|
Hello All,
I’m developing an app which has set FormBorderStyle = None, as any developers who have already developed this type of app will know, there is no ControlBox/System menu available when right clicking the form icon. This is true for all WindowStates: minimized, normal or maximized.
Is there a way to show the controlbox/system menu while keeping FormBorderStyle = None (or any other work-around) .
I would be very grateful if there’s anyone out there who can help me out with this.
Thanks for your time & help,
Rob.
|
|
|
|
|
add a popup menu to the form, so the user can minimize/maximize the form by right-clicking on the form and choosing the state.
~~~ From Milano to The Hague, easy as it goes ~~~
|
|
|
|