|
Hi,
I also have sometimes the problem that I want to "wait" for a short time (some 10 or 100 milliseconds) and so far I helped myself with Timer and Thread.Sleep... (shame on me but I didn´t know better)
Is there any article or a short example how to do this correctly with Background worker?
Thanks
Thomas
|
|
|
|
|
ThomasManz wrote: Is there any article or a short example how to do this correctly with Background worker?
Yes, Using background worker you can show the progess on UI and aswell as do the process on backgronud.
Here is one sample application.
Using the BackgroundWorker Component in .NET 2 applications
Hope this is Help to you
|
|
|
|
|
therealrustyspork wrote: private void timer1_Tick(object sender, EventArgs e)
{
progressBar2.ForeColor = Color.Firebrick;
Thread.Sleep(50);
progressBar2.ForeColor = Color.Black;
}
You shouldn't use Thread.Sleep in GUI thread, but if you really want to, you need to redraw the progress bar.
private void timer1_Tick(object sender, EventArgs e)
{
progressBar2.ForeColor = Color.Firebrick;
Application.DoEvents();
Thread.Sleep(50);
progressBar2.ForeColor = this.ForeColor;
}
Greetings - Jacek
|
|
|
|
|
My question is how to create this: for an existing object a new custom property?
"existing object"= an object control in general (ex: a textbox)
"new custom property"= by default this control "textbox" have this property:
textbox.Hide();
...and many other properties off course,but I snipe to this particular one, only.
In what way? Well, I want that a single button to have a custom property write by me, named "myHideShowProperty" that can do 2 things in one package, I mean that when I click once, "Show" that textbox ; and when I click one more time it "Hide" that textbox, then when I click once more it "Show" a textbox,and so on.
In the end, the code I imagine that it must look like this:
btn1.myHideShowProperty.show(textbox);<br />
btn1.myHideShowProperty.hide(textbox);
The idea behind all of this is how to write a customized property for an existing object control.
And of course a solution for my problem, if there is one.
though I must mention that I have made a variant and it works:
private void button1_Click(object sender, EventArgs e)<br />
{<br />
button1.Hide();<br />
button3.Show();<br />
button3.Text = "second btn";<br />
}<br />
<br />
private void button3_Click(object sender, EventArgs e)<br />
{<br />
button3.Hide();<br />
button1.Show();<br />
button1.Text = "first btn";<br />
}<br />
|
|
|
|
|
The normal way is to derive a new class from the control
public class Foo : Button
but there is another way in VS2008 : Extension methods[^] which does exactly what you are asking for.
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
The same btn click event who can switch between 3 strings like "Aa", "Bb","Cc"?
1 click pop up the first string, second click(same btn) pop up the second string, and the third click(same btn) the last string?
And after the third one it begin with the first string, second,etc.
|
|
|
|
|
Hello, I'm currently teaching myself asynchronous socket programing. Should mention I got the code here http://www.codeguru.com/csharp/csharp/cs_network/sockets/article.php/c8781#Client6[^] and have been editing it and improving it.
Anyway the problem I'm having is after I kick someone for trying to use a name someone else has or they change their name while they are connected to a name someone else has, a rouge string "\0" is sent seemingly from the client, even though when I kick the client and the socket is closed he still manages to send it. I know it happens after I send a message to the client.
The reason that this is kinda of a problem is because I'm using substring and of course the string is just too short.
I know I can just use an if sentence that makes it ignore everything that is fewer than x characters but I really want to know where this rouge text string is coming from.
Can someone help me?
Sorry about not posting the code but it is very long and I can't really pinpoint where the error is.
modified 27-Feb-21 21:01pm.
|
|
|
|
|
Tumminn wrote: The reason that this is kinda of a problem is because I'm using substring and of course the string is just too short.
So, before getting the substring, make sure the input is long enough. It is the programmer's job to validate the input and to manage whatever happens. It may well be that the client app is sending the string when it disconnects, but why are you even trying to process a message from a client session that yoou have rejected?
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
That is not my intention it just happens, I just want to know the reason for why I get this data. It only happens if I send a message to him then I get the string "\0" back for no reason.
Also I know about validating bit but I'm just curious why it happens.
modified 27-Feb-21 21:01pm.
|
|
|
|
|
Is the client your own code too? Welcome to the wonderfull world of debug!
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
Okay fixed the part about the changing names while server is live but still have the problem of it trying to receive data from a socket that is closed, which it shouldn't do but does anyway just to spite me.
This is the code to closing the socket (Server Side)
string msg = "Name Taken";
byte[] byData = System.Text.Encoding.Default.GetBytes(msg);
socketData.m_currentSocket.Send(byData);
socketData.m_currentSocket.Close();
m_workerSocketList.Remove(socketData.m_currentSocket);
m_clientCount--;
This is the code where is error happens (Server Side):
try
{
if (pfnWorkerCallBack == null)
{
pfnWorkerCallBack = new AsyncCallback(OnDataReceived);
}
SocketPacket theSocPkt = new SocketPacket(soc, clientNumber);
soc.BeginReceive(theSocPkt.dataBuffer, 0, theSocPkt.dataBuffer.Length, SocketFlags.None, pfnWorkerCallBack, theSocPkt);
}
catch (Exception se)
{
MessageBox.Show(se.Message);
}
And last bit the client does when it is kicked:
if (m_clientSocket != null)
{
m_clientSocket.Close();
m_clientSocket = null;
UpdateControls(false);
}
Any ideas?
modified 27-Feb-21 21:01pm.
|
|
|
|
|
I am just guessing here. Is the listener fully disconnected from the serve before or after sneding the FOAD message to the client? Try either removing the listener side of things BEFORE the disconnect message or WAITING for a disconnect from the client. I prefer teh first of the two.
If you have disconnect from the server end, then there is no way that the client can send you any EOS messages which is what I think you are getting.
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
I'm not quite sure how to do what you mean, thought I had done that by removing and closing the socket. Could you explain or give an example?
Also what does FOAD and EOS mean?
I'm still a little wet behind the ears here since I'm teaching myself this, so I apologize for the beginner questions.
modified 27-Feb-21 21:01pm.
|
|
|
|
|
When you create the listener, you attach it to a listener event handler these need to be removed as well as releaseing the handle to the listener.
[FOAD - .... And Die, EOS - End of Stream]
[added]
These are not beginer questions, you're doing okay!
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
But if I were to release the listener wouldn't that mean that no more people could connect to the server?
Even if I did it temporarily wouldn't that dead period block people off from connecting?
Should have gotten the FOAD meaning though
modified 27-Feb-21 21:01pm.
|
|
|
|
|
Not having the /exact/ code you are using, makes this an answer in theory.
When you receive the connection, you validate the session and give the session listener a handler that will process the events:
listener.DataReceived += new System.EventHandler(server_DataReceived);
When the sesseion is being disconnected, you need to disconnect the lsitener:
listener.DataReceived -= new System.EventHandler(server_DataReceived);
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
|
Hi Friends,
I'm Harry actually i'm fresher student in software engeenring line and i'm doing aa activity . I created a login form in Microsoft Visual Studio 2005 and I'm trying to store user id and password on back end. And I'm using this code for this purpose but every time it shows an error and error is when every time i fill the user id and pasword and i just click on login button and message box appear with meesage user id and password is wrong. plz help me in thsi activity. down here the code plz check it out the error .
private void button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=DEVILINSIDE\\SQLEXPRESS;Initial Catalog=master;Integrated Security=True");
SqlDataAdapter da = new SqlDataAdapter("select * from loginform", con);
con.Open();
SqlCommandBuilder cmb = new SqlCommandBuilder(da);
DataSet ds = new DataSet("dataset");
da.Fill(ds, "loginform");
DataTable dt = new DataTable();
dt = ds.Tables["loginform"];
foreach (DataRow dr in ds.Tables["loginform"].Rows)
{
if (textBox1.Text == dr[0].ToString() && textBox2.Text == dr[1].ToString())
{
welcome w = new welcome();
w.Show();
}
else
{
MessageBox.Show("Invalid User Name or Password", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
textBox2.Text = "";
}
}
|
|
|
|
|
First of all you are doing this the Wrong way
First Create a Stored Procedure that does this
Create Procedure prclogin_check
(
@User_name varchar(20),
@U_Password varchar(23),
@Results int Output
)
IF EXISTS (Select * from User_Table
where User_name =@User_name and U_Password = @U_Password)
Set @Results =1
And after you are done with this , you have to do the Following in your C# Code
using System.Data.SqlClient;
String strcon = "User id = sa;Password= topman;Server=myServer;Database=MyDB";
SqlConnection con = new SqlConnection(strcon);
SqlCommand cmdselect = new SqlCommand();
cmdselect.CommandTimeout = 0;
cmdselect.CommandType = CommandType.StoredProcedure;
cmdselect.Connection = con;
cmdselect.CommandText = "prclogin_check";
cmdselect.Parameters.Add("@Results",SqlDbType.Int,4);
cmdselect.Parameters["@Results"].Direction = ParameterDirection.Output;
int Res;
try
{
con.Open();
cmdselect.ExecuteNonQuery();
Res = (int)cmdselect.Parameters["@Results"].Value;
con.Close();
}
catch (SqlException e)
{
MessageBox.Show(e.Message);
}using System.Data.SqlClient;
String strcon = "User id = sa;Password= topman;Server=myServer;Database=MyDB";
SqlConnection con = new SqlConnection(strcon);
SqlCommand cmdselect = new SqlCommand();
cmdselect.CommandTimeout = 0;
cmdselect.CommandType = CommandType.StoredProcedure;
cmdselect.Connection = con;
cmdselect.CommandText = "prclogin_check";
cmdselect.Parameters.Add("@Results",SqlDbType.Int,4);
cmdselect.Parameters["@Results"].Direction = ParameterDirection.Output;
int Res;
try
{
con.Open();
cmdselect.ExecuteNonQuery();
Res = (int)cmdselect.Parameters["@Results"].Value;
con.Close();
}
catch (SqlException e)
{
MessageBox.Show(e.Message);
}
And in your Business logic or in your Form you can create a Function that will test if the Count of Records is greater than 0,if its less than that , then its invalid login
Hope this Helps
Vuyiswa Maseko,
Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers."
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.somee.com
http://www.vuyiswamaseko.tiyaneProperties.co.za
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
|
|
|
|
|
Can anyone provide me with a code example of how to use a datetimepicker cell in datagridview where in the
datetimepicker column i can set the value of any cell to null or to any datetime according to my choice. And the format of the datetimepicker cell should be dd MMM yyyy. I checked a lot of examples in the forums including articles by Nils Jonsson, Pham Minh Tri and Claudio Grazioli but none of them works when the DGV is databound. It works till u can select a date in a blank cell and save it. But when u try to delete an existing date from a cell it generates error saying 'Formatted value of the cell has a wrong type'. There's no way I can set a null value in a databound cell. I'm fed up of this. Plz help.
|
|
|
|
|
Hi,
How to find whether horizontal scroll bar is moved right or left?
If its moved right then some code need to get execute and vice versa.
Thanks...
Reg,
Subbu
|
|
|
|
|
Two events to look at:
private void hsc_Scroll(object sender, ScrollEventArgs e) {
}
private void hsc_ValueChanged(object sender, EventArgs e)
{
}
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
This is the 5th version of the same question.
|
|
|
|
|
Hi, i would like to explain my problem. I want to see the code when my applcation generate an exception.
I create a simple application that crash when a button is pressed:
private void button1_Click(object sender, EventArgs e)
{
Int32 Text;
Object obj= null;
Text= (Int32)obj;
}
This code generate a NullReferenceException when it try to make a cast of "obj".
Now, i run .exe file on a pc with only VS2008,when i click the button,jitdebugger start and ask me where is the file .cs.
My questions are:
Why the jitdebugger ask me where is the .cs file?
If i open module page (ctrl+alt+u) i see my file .exe with symbols loaded, but i can see the c# code.
Help me please.
Thank you, have a nice day
bye bye
|
|
|
|
|
frommi wrote: Why the jitdebugger ask me where is the .cs file?
Did you actually create a deployment app or are you just copying the .exe from the bin directory to another computer? This will not work.
As for the error, you might want to try the following.
Text = Convert.ToInt32(obj);
This will run without creating an error.
Excellence is doing ordinary things extraordinarily well.
|
|
|
|