|
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 ~~~
|
|
|
|
|
Thanks for your reply Rey9999,
Yes I could add a Context Menu to the form, but the user has no access to it when the form is minimized to the taskbar, it's this which is my main problem.
Thanks for your time,
Rob.
|
|
|
|
|
you could minimize the form to the system tray instead, through a NotifyIcon control, which you can add a context menu to.
~~~ From Milano to The Hague, easy as it goes ~~~
|
|
|
|
|
I'm a C++ programmer trying to find his feet in the C# world. One problem I'm particularly struggling with is this. In C++ I used to have a handy little technique for populating a buffer according to certain rules.
Say for instance I have something like unsigned char xmt_buf[200] . Now the first 4 bytes of this buffer will be header information (it's all part of a transmission protocol). So I define the header structure as follows:
struct MessageHeader_t
{
unsigned char MessageFormat;
unsigned char MessageLength;
unsigned char MessageType;
unsigned char HeaderLength;
} MSG_HDR;
So far so good, but now for the part that I like and which I just can't implement in C#. When I populate the buffer I do something like this:
MSG_HDR *msghdr;
msghdr = (MSG_HDR *)&xmt_buf[0];
msghdr->MessageFormat = 0x23;
msghdr->MessageLength = 0x3E;
msghdr->MessageType = 0x61;
msghdr->HeaderLength = 0x04;
Of course then I can populate the remainder of the buffer in a similar way.
TAG_CON *connect;
connect = (TAG_CON *)&xmt_buf[sizeof(MSG_HDR)];
connect->TagType = 0x65;
connect->Priority = 0x01;
.
.
.
Maybe I'm not ready for ths type of thing in C# yet but if anyone can help, I'd be thrilled.
|
|
|
|
|
Which part are you having problems with?
Keep in mind, you can use pointers if you like; they just have to be wrapped up in an unsafe block:
unsafe
{
msghdr = (MSG_HDR *)&mt_buff[0];
}
Or just put unsafe in the method declaration.
public unsafe void DoIt() {...}
That said, typically there isn't a need to use pointers directly; typically one can just make use of reference types. If you need to pass a value type like a struct by reference, one can use the ref or the out keyword:
public void ModifyThisInt(ref int i)
{
i = 10;
}
int i = 0;
ModifyThisInt(ref i);
Console.WriteLine(i);
But to answer your question, can you be specific about what piece you're having trouble with?
|
|
|
|
|
Thanks for the help so far.
Judah Himango wrote:
msghdr = (MSG_HDR *)&xmt_buf[0];
Right there is where I get stuck. The above line gives me a compile error that reads:
You can only take the address of an unfixed expression inside of a fixed statement initializer.
I also have another problem which probably belongs in another thread but I'll throw it in just in case there's a quick answer to it. The struct that I quoted in my original message is a simplified version of what I had in C++. The real struct is not just a struct of byte values. Some of the members were arrays. Here is a more realistic version of the struct.
struct MessageHeader_t
{
unsigned char MessageFormat;
unsigned char MessageLength;
unsigned char MessageType;
unsinged char MessageFlags[6];
unsigned char HeaderLength;
} MSG_HDR;
In other words, after msghdr = (MSG_HDR *)&xmt_buf[0]; I can populate the msghdr variable which as the effect of populating the first 10 bytes of xmt_buf.
Important to note is that I'm not using the .NET 2.0 framework as I'm developing for a device running the Windows CE.NET OS with the older framework.
Thanks mate.
BTW - I like your blog.
|
|
|
|
|
Dewald wrote: msghdr = (MSG_HDR *)&xmt_buf[0];
OK, I use pointers so rarely I forgot that in C# you have to use the fixed statement around something you're taking the address of; "fixed" is required to tell the garbage collector to pin (not move) the object in memory while you hold a pointer to it. Otherwise your pointer could end up pointing to something else. So it'd look like:
fixed ( MSG_HDR* msghdr = &xmt_buf )
{
}
Something like that. You can read more about using unsafe code like this in this article[^].
Again, one typically does not need to use unsafe code in C#. You certainly can, but it's rather irregular. If you haven't already, you might want to have a look at the C# FAQ for C++ programmers[^]; kind of clarifies some things when you're coming from a C++ background. I found it quite useful when moving to C# myself.
When you said you're having trouble with the struct itself, was it because you were having trouble with declaring arrays? In any event, if I were to write the equivalent of that struct in C#, it'd look something like this:
struct MessageHeader
{
byte MessageFormat;
byte MessageLength;
byte MessageType;
byte[] MessageFlags = new byte[6];
byte HeaderLength;
}
Let me stress again I normally wouldn't write such code in C#. This sounds more like a task for a class than a struct (C# structs are very different than C structs). So I'd probably put this stuff in a class unless there's a real need to have it in a C# struct. Also, when you've got stuff in classes, it's common to make fields private, and supply property accessors to the data. So if I really wanted to be all .NET warm and fuzzy, I'd write it something like this:
public class MessageHeader
{
private byte format;
private byte length;
private byte type;
private byte[] flags;
private byte headerLength;
public MessageHeader()
{
}
public MessageHeader(byte format, byte length, byte type, byte[] flags, byte headerLength)
{
if(flags == null)
{
throw new ArgumentNullException("flags");
}
if(flags.Length != 6)
{
throw new ArgumentException("Flags must be 6 elements in length.");
}
this.format = format;
this.length = length;
this.type = type;
this.flags = flags;
this.headerLength = headerLength;
}
public byte Format
{
get { return this.format; }
set { this.format = value; }
}
public byte Length
{
get { return this.length; }
set { this.length = value; }
}
public byte[] Flags
{
get { return this.flags; }
set
{
if(value == null)
{
throw new ArgumentNullException("flags");
}
if(value.Length != 6)
{
throw new ArgumentException("flags must be 6 elements in length.");
}
this.flags = value;
}
}
public byte HeaderLength
{
get { return this.headerLength; }
set { this.headerLength = value; }
}
}
And from calling code, if I wanted to fill up that Flags array with data, it'd look something like this:
MessageHeader header = new MessageHeader();
header.Flags = new byte[] { 5, 240, 6, 29, 60, 152 };
Dewald wrote: BTW - I like your blog.
Thanks.
|
|
|
|