|
It a registry entry under the user. If you look up registry programing you can have a program call a .reg file and add a prog to startup automatically.
|
|
|
|
|
HKEY_LOCAL_MACHINE > SOFTWARE > MICROSOFT > WINDOWS > CURRENT VERSION > RUN.
If you only want to run the program once on start up (e.g not run on next startup), add the entry in HKEY_LOCAL_MACHINE > SOFTWARE > MICROSOFT > WINDOWS > CURRENT VERSION > RUNONCE
|
|
|
|
|
Hello,
I have a problem with asynchronous sockets communication. I try to send an object from the server to the client by using the send method. In the client's ReceiveCallback I have put two breakpoints, one at line "if (bytesRead > 0) " which is hit, and one at line " bgForm.ReceiveObject(state.gameDataStream);" which never gets hit. What could be the reason? Thanks in advance.
The client code:
public static void StartClient(string ServerIPAddress, int port)
{
// Connect to a remote device.
try
{
IPAddress ipAddress = IPAddress.Parse(ServerIPAddress);
IPEndPoint remoteEP = new IPEndPoint(ipAddress, port);
// Create a TCP/IP socket.
Socket client = new Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp);
connectDone.Reset();
// Connect to the remote endpoint.
client.BeginConnect( remoteEP,
new AsyncCallback(ConnectCallback), client);
connectDone.WaitOne();
Receive(client);
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
}
private static void ConnectCallback(IAsyncResult ar)
{
try
{
// Retrieve the socket from the state object.
Socket client = (Socket) ar.AsyncState;
// Complete the connection.
client.EndConnect(ar);
// Signal that the connection has been made.
state.workSocket = client;
connectDone.Set();
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
}
public static void Receive(Socket client)
{
try
{
// Begin receiving the data from the remote device.
client.BeginReceive( state.buffer, 0, StateObject.BufferSize, 0,
new AsyncCallback(ReceiveCallback), state);
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
}
private static void ReceiveCallback( IAsyncResult ar )
{
try
{
// Retrieve the state object and the client socket
// from the asynchronous state object.
StateObject state = (StateObject) ar.AsyncState;
Socket client = state.workSocket;
// Read data from the remote device.
int bytesRead = client.EndReceive(ar);
if (bytesRead > 0)
{
// There might be more data, so store the data received so far.
state.gameDataStream.Write(state.buffer,0,bytesRead);
receiveDone.Reset();
// Get the rest of the data.
client.BeginReceive(state.buffer,0,StateObject.BufferSize,0,
new AsyncCallback(ReceiveCallback), state);
receiveDone.WaitOne();
}
else
{
// All the data has arrived; put it in response.
// Signal that all bytes have been received.
receiveDone.Set();
}
bgForm.ReceiveObject(state.gameDataStream);
client.BeginReceive(state.buffer,0,StateObject.BufferSize,0,
new AsyncCallback(ReceiveCallback), state);
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
}
|
|
|
|
|
Unless I'm making a horrible mistake in reading your code, the flow goes something like this:
ReceiveCallback is hit, and proceeds through the following lines, in order:
<br />
if (bytesRead > 0)<br />
<br />
state.gameDataStream.Write(state.buffer, 0, bytesRead);<br />
receiveDone.Reset();<br />
client.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0,<br />
new AsyncCallback(RecieveCallback), state);<br />
receiveDone.WaitOne();<br />
The result is that inside your read you start waiting for the next read to finish. So, at least until something triggers receiveDone , the code will not reach your bgForm.RecieveObject(state.gameDataStream) function.
You will need to rework the flow logic, so you can handle the data you just received before waiting for the next read, or triggere then next read and handle your data without waiting for the next read to finish.
John
"You said a whole sentence with no words in it, and I understood you!" -- my wife as she cries about slowly becoming a geek.
|
|
|
|
|
Hi John,
thanks for the reply. I'm not quite sure how EndReceive() works and when it returns 0 bytes read. I was hoping that it reads the chunks of the data and when finishes and 0 bytes are read performs receiveDone.Set() and than I get the full data and deserialize the stream. If I remove WaitOne() from the code I get an error "Failed to deserialize. Reason: end of stream encountered before parsing was complete." I guess it is a synchronization issue but can't find the solution by myself, so any advices are appreciated.
Regards
|
|
|
|
|
Well, your code doesn't show the attempt to actually read from the socket. So, I assume that you have dropped the information in bytesRead by the time you get to the routine that actually reads the data. If that is correct, you are simply trying to read more than there is available to be read.
It also sounds as if you are using serialization, which I haven't worked with. Much of my socket work has been with manual code to interpret what is being sent.
John
"You said a whole sentence with no words in it, and I understood you!" -- my wife as she cries about slowly becoming a geek.
|
|
|
|
|
As I see the read process it begins with calling BeginReceive() where I set the size of the chunks to read from the network stream. The actuall read of a chunk ends with EndReceive() and in this moment a check for 0 bytes read is performed. If the result is not 0 than BeginReceive() on the socket is called again, the next chunk is read and stored in the Stream field which I need to deserialize.
|
|
|
|
|
I see your confusion. The read process goes like this:
1. Call BeginRead()
2. The code enters your read callback when data is ready
3. You see how many bytes you have now in bytesRead
4. Take the bytes you want out of the read buffer.
5. Use these bytes before calling BeginRead() with the same buffer.
6. Look back to step 1 until you're done.
John
"You said a whole sentence with no words in it, and I understood you!" -- my wife as she cries about slowly becoming a geek.
|
|
|
|
|
When i load dialog box on top of my activex control twice,my web page getting stuck.
how can i solve this problem.
thanks
|
|
|
|
|
Hello Everyone!
Well, as the header states, I don't get the Parse Event raised/fired.
This is my situation:
I have a DateTimePicker and a checkbox infront of it.
Parse Event:
If the checkbox is unchecked, the DataBinding is supposed to write null into the database (this means that the structural design wo which this date belongs hasn't been released).
Is the checkbox checked, the Value of the DateTimePicker is supposed to be written in the database.
FormatEvent:
If the field in the database contains a null value, the checkbox gets disabled (and so through another event the DateTimePicker).
Is there a date in the database, the checkbox gets enabled and marks the structural design as "released".
Well, the Format Event works fine, the Parse does nothing.
From the MSDN I understand that it gets raised under three conditions:
* after the Validated event of the Control object occurs.
* when the EndCurrentEdit method of the BindingManagerBase is called.
* when the Current object of the BindingManagerBase changes (in other words, when the Position changes).
I tried to force all of them, nothing happens.
Well here is my Code:
The Binding:
Binding bind = new Binding("Text", Ergo.MainApp._DesignDB._SelDesignDV, "Freigabe_Datum");<br />
bind.Parse += new ConvertEventHandler(bind_Parse);<br />
bind.Format += new ConvertEventHandler(bind_Format);<br />
this.dTP_Freigabe.DataBindings.Add(bind);
The Events:
private void bind_Format(object sender, ConvertEventArgs e)<br />
{<br />
if (e.Value == System.DBNull.Value)<br />
this.chBx_Freigabe.Checked = false;<br />
else<br />
this.chBx_Freigabe.Checked = true;<br />
}<br />
<br />
private void bind_Parse(object sender, ConvertEventArgs e)<br />
{ <br />
<br />
MessageBox.Show("Holla");<br />
if (!this.chBx_Freigabe.Checked )<br />
e.Value = System.DBNull.Value;<br />
}
Here I get the Currency Manager:
myCM = (CurrencyManager)BindingContext[Ergo.MainApp._DesignDB._SelDesignDV];
Here I tried to call EndCurrendEdit():
BindingContext bc = this.BindingContext; <br />
bc[Ergo.MainApp._DesignDB._SelDesignDV].EndCurrentEdit();<br />
myCM.EndCurrentEdit();
and here is the DataBase Update:
public void UploadDataView(BindingContext bc)
{ <br />
bc[selDesignDV].EndCurrentEdit(); <br />
OleDbCommandBuilder cb = new OleDbCommandBuilder(designDA); <br />
try <br />
{ <br />
designDA.Update(designDS, "Zeichnungen"); <br />
} <br />
catch(Exception ex) <br />
{ <br />
MessageBox.Show(ex.Message, "Fehler beim Upload der Daten - UploadDataView"); <br />
} <br />
}
The DateTimePicker is bound to a DataView.
All other bindings in my form (without events) are working fine, so I guess the problem is just the raising of the Parse Event.
I even included a Validated Event, but that didn't do it either...
Every help is GREATLY appreciated, since this is the only thing that stops the first part of my program from beeing finished...
And did I mention that I have absolutly the opposite of much time?
|
|
|
|
|
I would like to register a set of hotkeys for my TextBox
For example, when I press Ctrl+0 or Ctrl+N, the Text property of TextBox will be set to "<null>" string.
Any suggestion?
|
|
|
|
|
|
I have a tiff file that I need to dispay on a form. The picture box class apparently does not support tiff. I can convert the file to Bitonal but the image loses a lot.
Being fairly new to C# can someone recommend a way to accomplish my task of opening a tiff file into a windows form? (picturebox or whatever?)
thanks.
Bob
|
|
|
|
|
You are right. I was surprised the designer doesnt support it. Try it this way:
pictureBox1.Image = new Bitmap("C:\\test.tif");
|
|
|
|
|
Is there any other way to calculate network utilzation except using PerformanceCounter ??
|
|
|
|
|
I am wondering if there is way to keep the nice method descriptions, available at programming time, if you compile the class to .dll. Will be nice for fellow programmers when using my classes.
|
|
|
|
|
Yes. Use XML documentation (3 forward slashes), and go into your project properties and enable XML documentation file. Name the xml documentation file <yourdllname>.xml
When other developers go to use your dll, IDEs such as Visual Studio will realize there is a documentation file available, and will use that to populate intellisense.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: The Secular Left, the Religious Right, and Prejudice
Judah Himango
|
|
|
|
|
Thanks - This helps me alot
|
|
|
|
|
Go take a look at NDOC.
http://ndoc.sourceforge.net
it is free and allows you to document your classes from inside your code and build a MSDN type class reference file that can be used within or outside of your assembly.
Bob Robey
|
|
|
|
|
After you have enabled the xml docs ,then :
In commenting claases and methods just use before them
///<summary>
///Summary description for Your class or Method.
///</summary>
If you want to comment a parameter then use:
/// <summary>
///
/// </summary>
/// <param name="Your Second parameter name"></param>
/// <param name="Your First parameter name"></param>
as < summary >s stands to the method description and param to the parameters ,and you can use any number of parameters.
|
|
|
|
|
I did drop only two TextBox-es one for username next for password.
But how can i write code to checked in SQLServer username and password then to back me response???
|
|
|
|
|
1 :When you reply just click on the message and then there is a link called reply just click on it ,instead of launching a new thread.
2 : Create a database and then any table in it called USERS for example ,and add fields called username and password ,etc... .
And then try to ckek it by using a datareader to check if it's in the database or otherwise.
|
|
|
|
|
In one my appliation whicha i create by C# i need in page_Load to show me a new form in wich I must give username and password. So can somebody help me how to coding for username and password which's must analysed in SQLServer then to get back me a response.
If username and password is incorrect get error.
If username and password is correct get show next page.
HELP
|
|
|
|
|
Try to make another form in your project that contains only 2 textboxs ,and then try to code this ,and if any problem presents we will help you so much more.
|
|
|
|
|
I am trying to create a main table from a dataset that may have mutiple tables all with the same structure any clues. I need to end up with one table at the end where am i going wrong as i get the error table1 already belongs.
here is my code
//get all table into one ready to show and print
DataTable tblNew;
tblNew = dst.Tables[0].Copy(); //get the sructure and data
for(int i = 1;i
|
|
|
|