|
I'm assuming that "\r\n\r\n" is the marker you are trying to use to indicate the end of the stream. You would want to do something like this:
string ami_response = "";
if (ami_client_stream.CanRead)
{
byte[] ami_response_buffer = new byte[ami_buffer_size];
MemoryStream ami_memory_stream = new MemoryStream();
int ami_bytes_read = 0;
myCompleteMessage = new StringBuilder();
do
{
ami_bytes_read = ami_client_stream.Read(ami_response_buffer, 0, ami_response_buffer.Length);
myCompleteMessage.AppendFormat("{0}", Encoding.ASCII.GetString(ami_response_buffer, 0, ami_bytes_read));
}
while (ami_client_stream.DataAvailable);
ami_response = myCompleteMessage.ToString();
}
return ami_response;
|
|
|
|
|
Hi,
My win form is always getting minimized after splash screen is shown and closed. Although my form's WindowState property is set to Normal. Is there any code piece I am missing to keep my original window STAND !!
Thanks.
/********************** My code ****************************/
public mainForm()
{
InitializeComponent();
th = new Thread(new ThreadStart(DoSplash));
th.Start();
}
private void DoSplash()
{
sp = new Splash();
sp.ShowDialog();
}
private void mainForm_Load(object sender, EventArgs e)
{
th.Abort();
}
|
|
|
|
|
Hello
1- First, the code above -AFAIK- shouldn't minimize your original form. Yet you might be missing something else somewhere!!
2- Second, the code above is a bit odd. Why do you call ShowDialog from another thread while simply you could just show the form in your own thread -make things simple!!-.
private void mainForm_Load(object sender, EventArgs e)
{
Splash MySplash = new Splash();
MySplash.Show();
MySplash.Close();
}
I guess you are making a splash while loading your form -which might be a lengthy process in your case-. Maybe you minimized you main form somewhere while loading its UI?!!
Regards
|
|
|
|
|
Dear Nader,
the reson why you put a splashscreen in a separate thread is that otherwise the splashscreen isn't updated while the main thread is busy doing other things.
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
Hello Mav
Nice to see you on the forum today
Danke für den tipp!
Regards
|
|
|
|
|
Hi!
There's no reason in the code you showed us why the main form should be minimized.
But another point I noticed was your use of Thread.Abort() .
Usually this is considered bad practice - it's better to let the thread exit gracefully.
You could do this by adding a method
private void CloseSplash()
{
sp.Close();
} and calling sp.BeginInvoke(new MethodInvoker(CloseSplash)); instead of th.Abort() .
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
Hi Mav,
Thanks for your time. AS you said, I should use,
sp.BeginInvoke(new MethodInvoker(CloseSplash)); instead of th.Abort(). Is it because I am doing inter threaded operation ?
Regards,
|
|
|
|
|
Exactly.
If you're just calling sp.Close() you'll get an IllegalInterThreadOperationException.
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
Hi,
I have multiple threads in my Win application and those retrieve connection string from app.config file concurrently. Although each thread use its own sql connection instance, yet I was worried to think that, if there is any chance to get crash when those threads reading the app.config file to get the connection string concurrently ? In that case Do I need to Lock the config file ?
The snippet I use for retrieving the connection string as follows :
SqlCeConnection myConn = new SqlCeConnection(ConfigurationManager.ConnectionStrings[1].ConnectionString);
Thanks and regards
|
|
|
|
|
Unless you plan to edit them at runtime (possible with the ConfigurationManager ) then no. Race conditions only matter, and therefore have to be prevented, if threads are reading and writing concurrently. They do also matter if threads are writing concurrently and you care about which result is written.
|
|
|
|
|
Hi Mike, thanks for your reply.
So, as my situation is just only reading connection string and no writing or editing, so I dont need to worry about Locking. RIGHT ?
Thanks and regards,
Emran
|
|
|
|
|
|
hi everybody,
i was given a job of developing a function which accepts 3 parameters i.e., an assembly path, a class with namespace, and a method in that assembly. the function should return the value that is being returned by the method that iam invoking(the one which we passed as a parameter)
iam using system.reflection namespace.
the problem is, i also need to pass arguements to the method that iam invoking but it is just not working the i way i want. this is how iam calling my function ..
public int myreflect("..the path of the assembly..", "...calss name with namespace..say N.C1..","..method name..say M1..", 2,4) // 2,4 are the arguments iam passing to my method M1//
this is how iam defining my function
public int myreflect(string a, string b, string c, params int[] list)
everything is working except that i need to somehow extract the arguements which are in the param array i.e., list.
i need to capture those arguments and store them in another array..say int[] args..and use this args in Invokemember function, as parameters to invoke my M1 method. i hope i have done a fair job in explaining my problem. a little help would be greatly appreciated. Thanks in advance....
Sonu
|
|
|
|
|
As InvokeMember takes an object array, copy the content of the integer array into such an array and then pass it to InvokeMember .
object[] args = new object[list.Length];
list.CopyTo(args, 0);
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
Thanx Stefan!!
this is exactly what i wanted.
iam gratefulto you....thanx once again..
Sonu
|
|
|
|
|
Hi
How can I have Windows open a file using the default program? eg. ".txt" files open with notepad, etc.
Thanks (The function's at the back of my head somewhere, but I just can't find it... )
|
|
|
|
|
thepersonof wrote: The function's at the back of my head somewhere, but I just can't find it...
Look for the brain cell labeled Process.Start and you found it
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
|
Hi
I'm just wondering why I can't use the PropertyInfo class to set the value of a property if I'm using the implicit conversion operator?
How do I get around this problem? I want to use the PropertyInfo.SetValue function, but I need it to work with all datatypes.
Thanks
/mj
==========================================================
Guid oId = new Guid();
MyGuid oMyId = new MyGuid();
MyClass oClass = new MyClass();
PropertyInfo oInfo = oClass.GetType().GetProperty("Id");
oClass.Id = oMyId; // fine...
oClass.Id = oId; // this works fine!
oInfo.SetValue(oClass, oMyId, null); // this is also fine
oInfo.SetValue(oClass, oId, null); // but this doesn't work!!?
==========================================================
These are my classes
==========================================================
public class MyClass
{
private MyGuid m_oId;
public MyGuid Id
{
get { return m_oId; }
set { m_oId = value; }
}
}
public class MyGuid
{
public MyGuid()
{
m_oId = new Guid();
}
public MyGuid(string p_sId)
{
m_oId = new Guid(p_sId);
}
public MyGuid(Guid p_oId)
{
m_oId = p_oId;
}
private Guid m_oId;
public static implicit operator string(MyGuid p_oId)
{
return p_oId.m_oId.ToString();
}
public static implicit operator MyGuid(string p_sId)
{
return new MyGuid(p_sId);
}
public static implicit operator Guid(MyGuid p_oId)
{
return p_oId.m_oId;
}
public static implicit operator MyGuid(Guid p_oId)
{
return new MyGuid(p_oId);
}
}
|
|
|
|
|
hi
What event is fired when the exit ("X") button of a form is clicked (but before the form closes)?
thank you for your help
|
|
|
|
|
Form.Closing or Form.FormClosing in .NET 2.0 respectively.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
|
Can anyone tell me how to "deeply" refresh property grid. That means after refreshing it all attributes attached to its SelectedObject's properties will be reloaded.
I have tried the following:
1. propertyGrid.Refresh(); // Doesn't work
2. propertyGrid.SelectedObject = PropertyGrid.SelectedObject; // Doesn't work
3. object obj = propertyGrid.SelectedObject;
propertyGrid.SelectedObject = null;
propertyGrid.SelectedObject = obj; // Doesn't work.
I try also to assign a new object (of the same type that was assigned to the propertyGrid) to another property grid but the second property grid still displayed the cached attributes.
It seems that the .net framework cache the attributes assigned to the selected object, but how can i clear that cache - or at least make the framework reloads these attributes.
The reason i want to do so is to enable runtime switching between different languages. My overriden Description, Category And DisplayName attributes loads values depends on the current thread culure UI.
Any suggestions?
Thanks
|
|
|
|
|
Dear Friends
I've bound the DataGridViewComboBoxColumn to a table in Database, and I want programmatically to change the index of the selected item in the DataGridViewComboBoxCell, and I didn't find any property to do that
kindly help me to do this...
|
|
|
|
|
Hello
Your title was about assigning values. This means True or false valus to the cells. This is done simply by changing the DataGridViewCheckBoxCell.Value property to either true or false.
OTOH in your post you said you want to change the index!! this is considered more with rows not columns. If you want to change the display index of a row -Move it up or down in the grid-:
DataGridViewRow MyTempRow = MyDataGridView.Rows[OldIndex];
MyDataGridView.Rows.RemoveAt(OldIndex);
MyDataGridView.Rows.Insert(NewIndex, MyTempRow);
PS.I used OldIndex/NewIndex naming conventions just for the sake of clarity. If you want to get the first selected row use MyDataGridView.SelectedRows[0], provided that you check it is not null first.
Regards
|
|
|
|