|
A few suggestions :
- from the code above, you are creating an object of type Form2 , and then store its reference to a variable of type Form . Although this could be ok, it's likely you are misusing the object types. Use this instead : Form2 frm = new Form2() .
- to make sure a method can be called from the outside, just add the public attribute on the left of the return type. For instance, public void Initialize() { ... }
|
|
|
|
|
Basically i have created a windows service for the purposes of logging events, exceptions etc to a central database. The windows service gets the objects (ie info object, warning object, excepiton object etc) from a MSMQ queue. Since I wanted to deploy the whole thing a bit easier (in case I needed to move it), I created a web service so that my other apps call the webservice with the message to log, and the webservice takes care of putting the object into the queue which is monitored by the windows service.
Heres my question (finally). What are the rules for objects being deserialized and serialized, with respect to does the assembly doing the serializing need to know of the types it it serializing, or can it just know of the base type etc?
TIA
Andy
He who knows and knows that he knows, is wise; follow him
He who knows and knows not that he knows, is asleep; wake him
He who knows not, and knows that he knows not, is simple; teach him
He whoe knows not and knows not that he knows not, is a fool; kick him
|
|
|
|
|
I have some code that reads from a NetworkStream, retrieving both standard strings as well as binary data. The following code works:
connection_ = new TcpClient(host, port);
connection_.ReceiveTimeout = 30000;
stream_ = connection_.GetStream();
bufStream_ = new BufferedStream(stream_);
reader_ = new StreamReader(stream_, Encoding.GetEncoding("iso-8859-1"));
string str = reader_.ReadLine();
byte b = (byte)bufStream_.ReadByte();
But it's a little weird because the reader goes directly against the network stream for reading full lines as strings, but it goes through the buffered stream when reading individual bytes. Even though this works, I tried the following change:
reader_ = new StreamReader(bufStream_, Encoding.GetEncoding("iso-8859-1"));
But this doesn't work at all. When it gets to the ReadLine, it blocks indefinitely. Could this be a bug in BufferedStream? I'm using .Net 1.0, by the way.
|
|
|
|
|
I got around this problem by writing my own "ReadLine" for the buffered stream, eliminating the need for the StreamReader. Here it is, if you are interested. Please excuse the use of "goto", but it was the most natural (and efficient) way to write the code:
private string ReadLine()
{
StringBuilder sb = new StringBuilder();
byte b;
<BR>
p0:
b = (byte)bufStream_.ReadByte();
if (b != '\r')
{
sb.Append((char)b);
goto p0;
}
<BR>
p1:
b = (byte)bufStream_.ReadByte();
if (b != '\n')
{
sb.Append((char)'\r');
if (b == '\r')
{
goto p1;
}
else
{
sb.Append((char)b);
goto p0;
}
}
<BR>
return sb.ToString();
}
|
|
|
|
|
Is there a preference for Windows Forms programmers between overriding On{EventName} vs. adding an EventHandler for the {EventName} event?
For instance, override OnClick(...) vs. Click += new MouseEventHandler(this.ClickHandler).
Is either way more proper or efficient, etc.? I can understand that in certain cases, it makes sense to override OnPaint if you don't want the base OnPaint handler called, and things like that.
Thanks,
Arun
|
|
|
|
|
Generally speaking, it is better to override the On{EventName} methods first. The first reason is that the On{EventName} method will be called before the corresponding event is fired anyway, and the second reason is that overriding the method is more efficient than intercepting the event. Of course, that advice goes out the window if you aren't deriving from the class that is issuing the event(s). In that case, you will need to intercept the event itself.
|
|
|
|
|
I use a function from DLL that returns a char**:
extern char** GetNames();
Here my PInvoke declaration:
[DllImport("mydll.dll")]
static extern IntPtr GetNames();
So, I would like to know how I can get all strings in IntPtr?
Thanks!
|
|
|
|
|
There was a thread in this forum a couple of days ago called "Marshalling char**", which explained exactly that.
|
|
|
|
|
Can I make my own class that can be persisted to a resource and read back from it using ResourceManager.GetObject()? I ought to know this by now, but the only way to know is to find out. I've looked all over but haven't found any info yet. Does anyone know how it's done?
"Do unto others as you would have them do unto you." - Jesus
"An eye for an eye only makes the whole world blind." - Mahatma Gandhi
|
|
|
|
|
Hi...
I have some problems. I need to reboot my FTP service on my server trough an ASP.NET UI. I've tried to use Impersonate to gain administrator access, and use Processes to execute the command. This won't work, since impersonated access aint interhited to the process.
The next thing we tried, was to use some Windows API calls like CreateProcsessAsUser and CreateProcessWithLogonW, witch worked localy in a console app. (Used task manager to be sure the right user was executing the process). BUT, when using the exact same code, trough ASPNET, the ASPNET account was the account executing the .exe file.
So, witch options do i have? Anyone got file execution trough ASP.NET to work? This is driving me crazy.. Would love to se some code samples from people executing .exe files trough ASP.NET using C#.
*frustrated* confused:
|
|
|
|
|
A suggestion is to create a windows service. Doing so, you decide (service properties / LogOn tab) under which logon the service is running. Then build an ASP.NET page which awakes the service on demand.
|
|
|
|
|
Agree..
This was what i was thiking avbout, BUT, i have one concerne, witch is that the problem is not my code but BulletProf FTP server. The reason is that in the middle of my frustration a system SP in SQL Server came in mind: xp_cmdshell, witch allows
you to execute shellcommands on the server. I created a .BAT script rebooting the server. If i double clicked the .bat file, it rebootet my FTP server, but, if i simply typed "EXEC xp_cmdshell 'c:\myscript.bat'" nothing happened. This is realy strange!
I have never written any windows services, but i was thinking that this might be the solution. Once i have the service up and running, i can set permissions to the service, and access it trough ASP.NET?
Am i the only one experiencing these problems executing .exe files on the server..?
Tnx for the help so far..
PS! Other suggestions on how to reboot my FTP server is greatly appreachiated.
(Sorry my bad english, my head is getting tired, and my mother thounge is Norwegian..)
-Jonas
|
|
|
|
|
LogonAsUser maybe?
Paul Watson wrote:
"At the end of the day it is what you produce that counts, not how many doctorates you have on the wall."
George Carlin wrote:
"Don't sweat the petty things, and don't pet the sweaty things."
Jörgen Sigvardsson wrote:
If the physicists find a universal theory describing the laws of universe, I'm sure the a**hole constant will be an integral part of that theory.
|
|
|
|
|
Not sure if the WINAPI methods are the key. Since, the CreateProcess... methods worked just fine in a console app, but in a asp.net app, it simply wouldn't execute correctly. I did manage to execute the command as Administrator (according to the Task Manager) but, it didnt work... Anyone know if Bulletproof FTP Server have any issues like this?
Jonas
|
|
|
|
|
BulletProof FTP server have some inbuilt events. I use the OnHour event to execute a .bat file reloading the ini file.
But, i still would like to know how to achive this codewice....
Tnx for the help.
|
|
|
|
|
Hello again,
does anyone know how I would save a file using this path "%userprofile%" I've tried numerous ways but can't do it. I'm trying to save a file in a users home directory on Windows 2000
Thanks again.
- monrobot13
|
|
|
|
|
String szuserprofilevar = "%userprofile%";
String szuserprofile = Environment.ExpandEnvironmentVariables(szuserprofilevar);
|
|
|
|
|
Thanks for the help.
- monrobot13
|
|
|
|
|
i need a webpage show source code to draw element model (artifacts) like Rose or Visio adn by C#. Please give me.
Thanks
|
|
|
|
|
A full fledged Windows Form app can run inside IE6, inside a web page. Now you need to find (or better, write it on your own) a Windows Forms which does draws object models. My suggestion is to look around gotdotnet.com samples, sourceforge,....
|
|
|
|
|
I need to change the local IP and local computer name in my C# app. I can set the IP using the ManagementObject, but I have not found a way to change the computer name.
-- Kevin
|
|
|
|
|
Hi All,
I'm having a problem that I hope will be simple to solve. I have a RichTextBox that I don't want to format text. By this I mean if I copy a piece of text that is say bold and italic when I paste it into the RTB I don't want it to have those characteristics (unless the Font specified for the RTB has them). For an example lets say that font in my RTB is 8pt and I copy something that is 14pt when it's pasted it gets pasted at 14pt, I don't want that. Is there any way to get around this?
Thanks
- monrobot13
|
|
|
|
|
Figured it out. Just had to use a plain text (DataFormats.Text) format in the Paste method.
Thanks
- monrobot13
|
|
|
|
|
I have a DataGrid in my windows app. One of the fields is a date time type. It's showing up at a date in my DataGrid. I really need to see the time too. How can I change the format of this one field in the DataGrid?
|
|
|
|
|
To change the format of a column, you need to set the Format property of the DataGridTextBoxColumn corresponding to the column. See the example code under DataGridTextBoxColumn should help.
Burt Harris
|
|
|
|