|
Nothing!
System.Threading.Thread.Sleep(5000);
Or
using System.Threading;
Thread.Sleep(5000);
They're the same.
Maybe you should search for using Directive in MSDN.
When you're alone in the Dark, Fear will protect you...
|
|
|
|
|
The first is qualified with the full namespace, the last one isn't. The first one will always work, the last one only if you use the appropriate 'using'-clause.
Put the caret on the word 'Thread' of the second example, and hit the F12-button. What do you see now?
|
|
|
|
|
No Difference
Vuyiswa Maseko,
Sorrow is Better than Laughter, it may Sadden your Face, but It sharpens your Understanding
VB.NET/SQL7/2000/2005
http://vuyiswamb.007ihost.com
http://Ecadre.007ihost.com
vuyiswam@tshwane.gov.za
|
|
|
|
|
|
Hi All
Here is the code below
// List view items starts here.
ListView listView = new ListView();
listView.Bounds = new Rectangle(new Point(3, 16), new Size(900,900));
// Set the view to show details.
listView.View = View.Details;
// Allow the user to rearrange columns.
listView.AllowColumnReorder = true;
// Display check boxes.
listView.CheckBoxes = true;
// Select the item and subitems when selection is made.
listView.FullRowSelect = true;
// Display grid lines.
listView.GridLines = true;
listView.Visible=true;
listView.Columns.Add("File Name", 100, HorizontalAlignment.Center);
listView.Columns.Add("File Location", 100, HorizontalAlignment.Center);
listView.Columns.Add("File size", 100, HorizontalAlignment.Center);
// Add the ListView to the control collection.
this.Controls.Add(listView);
The text in first column header is aligned to left although i have aligned it to center.
The text in other two columns header is aligned to center as set by me.
How can i make the text in first column header to aligned centerally.
Thanks in advance
THE SK(Sandeep Kalra)
I am the One
|
|
|
|
|
Im converting all code from ADO.net to LINQ. In ADO i could add a DateTime field into SQL when adding a record. Im doing the same with LINQ & im getting an error. SqlDateTime Overflow. Must be between 1/1/1753 12:00:00 AM AND 12/31/9999 11:59:59 PM. My format is 2008/11/03 11:00:00 AM. How can I make it take this format & store it in sql server as the required format & not throw this error ?
|
|
|
|
|
There is no standard date format that looks like that. Try the ISO 8601 format "2008-11-03 11:00:00" instead. Otherwise you would have to use the DateTime.ParseExact method with the date format "yyyy/MM/dd HH:mm:ss" to parse the string into a DateTime value.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Thx Guffa
I found the problem. A DateTime null in link is not a null in sql. I was only passing one DateTime value & thinking the other DateTime will be null. I passed both DateTime values & no error.
|
|
|
|
|
Hi All,
Please can you assist me with this?
I got this app the imports data from a csv file to the database. The format has changed to Day,Visitors
"October 21, 2008",312 at the day column this the data that goes with this col "October 21, 2008" now i want the app to read whats after the " i want it to read 312.
Please can you assist me on this one?
Thank You
Ndeza,
|
|
|
|
|
I'm writing a simple multi-threaded TCP socket server, in which a new thread is created for each incoming connection (I only have to handle few connection so this should be ok). It is something like this:
static void Main(string[] args)
{
...
TcpListener listener = new TcpListener(IPAddress.Any, servPort);
listener.Start();
while(true)
{
try
{
Socket clntSock = listener.AcceptSocket();
MyProtocol protocol = new MyProtocol();
Thread thread = new Thread(new ThreadStart(protocol.HandleClient));
thread.Start();
}
catch (System.IO.IOException e)
{
...
}
}
}
public class MyProtocol
{
public void HandleClient()
{
...
}
}
I have several newbie questions:
1) How can I access data living in the worker threads? I was thinking to use properties in MyProtocol class for this purpose, like:
public class MyProtocol
{
public int Data
{
get { return _Data; }
set { _Data = value; }
}
private int _Data;
public void HandleClient() {...}
}
The main thread keeps a reference to the MyProtocol objects created, and uses the Data property to exchange data with the thread (with appropriate synchronization using lock to avoid race conditions). Is this ok? Is there any better approach?
2) Which is the correct way to shut down the connection threads? For example, if I want to close the server application, I think I should deal with terminating the connections in a correct manner.
Best regards,
Andrea
|
|
|
|
|
Metal76 wrote: The main thread keeps a reference to the MyProtocol objects created, and uses the Data property to exchange data with the thread (with appropriate synchronization using lock to avoid race conditions). Is this ok? Is there any better approach?
Yeah. This would be OK.
Metal76 wrote: Which is the correct way to shut down the connection threads?
I would add a Stop() method to MyProtocol class. See the below example
volatile bool canContinue = true;
public void HandleClient(){
while(canContinue){
......
}
}
public void Stop(){
canContinue = false;
} You need to call Stop on all the MyProtocol instances created.
Alternatively, you can make the thread as background.
MyProtocol protocol = new MyProtocol();
Thread thread = new Thread(new ThreadStart(protocol.HandleClient));
thread.IsBackground = true;
thread.Start(); So it ends when the main thread ends. But the first one would be the better choice.
|
|
|
|
|
Hi Navaneeth, thanks for fast and really useful reply! I have an additional doubt regarding thread shutdown. At the moment, the HandleClient() is something like this:
void HandleClient()
{
...
while ((recvMsgSize = clntSock.Receive(rcvBuffer, 0, rcvBuffer.Length, SocketFlags.None)) > 0)
{
...
}
}
So when shutting down the application I'd like to shutdown any active client connection and release any network resource. In order to use your solution (polling the canContinue flag) I think I should avoid blocking calls like the socket Receive() one. Am I right? And can you suggest a "graceful" way to shutdown alive connections?
Thanks in advance and regards,
Andrea
|
|
|
|
|
It depends from where you are calling Stop() method. If it is called from main thread, you can shutdown the socket inside the Stop() method. I am not sure that this is the graceful way.
|
|
|
|
|
Hi Andrea,
You should use one of the asynchronous patterns available on Socket : either BeginReceive or the new ReceiveAsync . It is not necessary ( or beneficial ) to create a thread for each connection.
BeginReceive[^]
ReceiveAsync[^], good example[^]
In answer to your questions:
1) To pass the received data to your main thread, MyProtocol should publish an event which it raises when a whole useful "message" has been received.
2) To handle application shutdown, keep a list of open sockets in MyProtocol and expose a method that, for each socket, sends any command messages required by the protocol to end the connection, and then calls Shutdown and Dispose on the Socket .
Nick
----------------------------------
Be excellent to each other
|
|
|
|
|
Thanks Nick, great suggestion! I have to work with a console application and I thought an event-based solution would not fit, but now I think I'll reconsider the whole approach.
Regards,
Andrea
|
|
|
|
|
This question has been asked, in one way or another, a few times and I've yet to see a solid answer.
I've searched the articles and messages but don't see a solution.
Here's my desire:
A normal ComboBox, when the DropDownStyle is set to ComboBox rather than ComboBoxList, will allow the user to select an item from the Items list OR type in their own value.
Near as I can tell, the DataGridView ComboBox performs validation to see if the Value matches an item in the list. If that Value is not found in the list, you get the error message:
"System.ArgumentException: DataGridViewComboBoxCell value is not valid"
Basically making the DataGridViewComboBoxCell function like a ComboBoxList -- in essence NOT allowing the user to type in a value that isn't in the list.
Is there a way around this? Is there a way for a DataGridViewComboBoxCell to allow the user to EITHER select a Value from the list OR type in a new value that is NOT already in the list?
I am definitely NOT the only one out here with this question / problem, so if you have any ideas on a way around it, PLEASE let us all know.
Thanks a bunch.
|
|
|
|
|
I found a little more info on this problem searching MS. Here's a comment:
The DataGridViewComboBox must hold all possible values that it will display
in it's items collection. For example, when binding to the Customers table
and having the CompanyName field a combobox the combobox must contain all
possible values. If the grid attempts to set the cell's value where the
combobox cell doesn't have the value then we throw the dataError event.
To workaround this, handle the DataError event of the DataGridView. For
example:
void dataGridView1_DataError(object sender, DataGridViewDataErrorEventArgs
e)
{
// ignore the data error occurring under the territoryComboBoxColumn
if (e.ColumnIndex != territoryComboBoxColumn.Index)
{
MessageBox.Show("Data error occurs:" + e.Exception.Message);
}
}
This tells us how to avoid the Exception. However, it doesn't address allowing the user's typed input to become the value for that cell.
Any thoughts?
|
|
|
|
|
Did you try this?
if (e.ColumnIndex != territoryComboBoxColumn.Index)
{
MessageBox.Show("Data error occurs:" + e.Exception.Message);
}
When you're alone in the Dark, Fear will protect you...
|
|
|
|
|
The best (and pretty much only) way I have ever found to address this kind of problem is to hook into the EditingControlShowing event of the DataGridView. When you do, you can detect that it is a ComboBoxCell being shown, and that the control is a DataGridViewComboBoxEditingControl (or something to that effect). This control is a very simple child class of the normal ComboBox control with a few extra properties for databinding in a data grid.
In the EditingControlShowing event, you can hook into the ComboBox as you normally would, and detect when its data changes and when it is closing. When it is closing, you can edit the data being bound to the ComboBox's available items list.
One caveat, I've never tried this. It may be impossible - I don't know exactly what order the DataGridView would carry out this operation (control closes->you add new item to bound data list->DataGridView validates the input against this new list). It may be that the data is validated before it will change the list of data, in which case you're up a creek unless you can find some way to add new items as the user is typing.
At any rate, if this is possible at all, you'll probably find some way to do it using this event.
There may be another way, and I'm all ears if there is - these are the kinds of problems I love solving with the DGV
|
|
|
|
|
Hi.
I have one form and three radiobuttons. Also, there are four numericUpDowns (two pairs of one for hours and one for minutes).
When a user clicks on one of the radiob. the action should change the minimum and maximum values of all the numUpDowns.
Well, the problem is - Only one works and only once.
The code is the same for all of them, only the numbers change :
private void rDop_CheckedChanged(object sender, EventArgs e)
{
// Setting the default limits for the arrival time of the selected work shifts
timeStartH.Maximum = 15; // end hour of shift.
timeStartH.Minimum = 7; // minimum arrival of shift.
timeEndH.Minimum = 7; // minimum end of shift.
timeEndH.Maximum = 15; // maximum hour of shift.
}
Ive tried with Click () action on radios but it does the same thing (logical).
Any ideas?
Thanks infront.
Matjaž
Força Barça!
|
|
|
|
|
What about the following :
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
if (radioButton1.Checked)
{
MessageBox.Show("Radio1");
}
}
private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
if (radioButton2.Checked)
{
MessageBox.Show("Radio2");
}
}
private void radioButton3_CheckedChanged(object sender, EventArgs e)
{
if (radioButton3.Checked)
{
MessageBox.Show("Radio3");
}
}
|
|
|
|
|
Thanks. Also tried this before but it cames the same. Maybe the problem is in valuechangers?
Força Barça!
|
|
|
|
|
Well, the problem is - Only one works and only once
Is this the radio button or the numeric up down..?
|
|
|
|
|
hmm i mistyped. it works only once for the change of numUpDown.
Força Barça!
|
|
|
|
|
Ok this works.... maybe i am misunderstanding your question...?
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
if (radioButton1.Checked)
{
numericUpDown1.ResetText();
numericUpDown1.Maximum = 15;
numericUpDown1.Minimum = 7;
numericUpDown2.ResetText();
numericUpDown2.Maximum = 15;
numericUpDown2.Minimum = 7;
}
}
private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
if (radioButton2.Checked)
{
numericUpDown1.ResetText();
numericUpDown1.Maximum = 10;
numericUpDown1.Minimum = 5;
numericUpDown2.ResetText();
numericUpDown2.Maximum = 10;
numericUpDown2.Minimum = 5;
}
}
private void radioButton3_CheckedChanged(object sender, EventArgs e)
{
if (radioButton3.Checked)
{
numericUpDown1.ResetText();
numericUpDown1.Maximum = 20;
numericUpDown1.Minimum = 3;
numericUpDown1.ResetText();
numericUpDown2.Maximum = 20;
numericUpDown2.Minimum = 3;
}
}
|
|
|
|