|
How do I access it's value? The below attempt is successfuly throwing a cast exception.
<br />
if (CheckState.Checked == (CheckState)dataGridView1.Rows[0].Cells[0].Value)<br />
{<br />
MessageBox.Show("ok");<br />
}<br />
|
|
|
|
|
so look at dataGridView1.Rows[0].Cells[0].Value.ToString() to discover what might be wrong.
everything responds well to ToString(), except null of course.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
Something's troubling. It requires me to "check" the checkbox at least once before checking it's VALUE to stop it from whining.
If I call
<br />
dataGridView1.Rows[0].Cells[0].Value.ToString()<br />
straight, without touching the grid, it's throwing NULL object exception.
|
|
|
|
|
Smith# wrote: It requires me to "check" the checkbox at least once before checking it's VALUE
Not quite. There must be many ways to make Value hold an appropriate value, or to overcome a possible null.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
The property Value will have value as true or false. Try casting that to boolean.
|
|
|
|
|
Please check my reply to Luc.
|
|
|
|
|
Essentially .Value can have 3 values in the case of a CheckBox : true , false and null . Whenever you deal with DataGridView cell values, you need to check for null . Whether it's a CheckBox cell or not, accessing a null is bad.
CQ de W5ALT
Walt Fair, Jr., P. E.
Comport Computing
Specializing in Technical Engineering Software
|
|
|
|
|
Hi Walt Fair, thanks for your reply. Well,I'm still not convinced with the replies.
The grid has been drawn on the screen, the rows have been created, the cells are displayed beautifully with checkboxes. Then why the "Value" has to be NULL? and why it's not NULL after I check the cell once?
|
|
|
|
|
Dear Sirs,
I've read google, MSDN and this site quite a bit and can't quite come up with the answer.
I've created a program (server) that is multi-threaded. Here are some descriptions:
Listener thread: This thread sits and listens for TCP connections. When it gets one, it creates a thread for that connection which gets data from that connection and interacts with the database, spawns processes, whatever the client asks for.
Scheduler thread: Certain tasks are scheduled to occur on the server, this thread sits tight and when the appropriate time (specified in config file) comes, it executes the tasks that need to happen one at a time (which then probably connect via the listener).
I would also like a GUI to monitor progress from the clients.
I currently have the following main method:
public static void Main(string[] args)
{
_con = new DW_DB_Connection();
Start_Threads();
}
If I use a GUI, I need STA Thread, right?
My question is this: does STAThreadAttribute diminish the power of my application to multi-thread aggressively (and allow it to scale quite large)?
From what I've read, it might be the case that STA only has an effect when the application uses COM (here). The scheduler and listener do not...I think, but Windows Forms certainly does. But other sources say it changes the apartment state of the current thread to be single threaded.
Let me know what you think.
In Christ,
Aaron Laws
http://ProCure.com
|
|
|
|
|
If you just create a new WinForms project, everything you need will be included. However,your threads cannot modify the UI directly. You need to use Invoke for that.There are several very good articles here on CodeProject about .Net multi-threading in a GUI.
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
Dear Mr. Simmons,
Thanks for the response. I'm not really multi-threading in a GUI, but my multi-threaded application uses a GUI. The UI is the last thing to be initialized. It's not much of a difference if any, but I thought I would point that out.
Beyond that, I'm just trying to make sure that my program in fact uses the .Net Free-Threading (right?) model, not a scheduled single-thread when I use the STAThreadAttribute . Thanks again.
In Christ,
Aaron Laws
http://ProCure.com
|
|
|
|
|
Hi,
this is how I understand the issue: the STA/MTA choice does not affect managed code; it exists in order to orchestrate how COM objects are used, i.e. in STA all COM accesses are sequenced, so no two threads are actively executing COM code. That would be relevant only in a few cases; only some GUI Controls force you to use STA, OpenFileDialog and similar dialogs are the most popular ones.
For a server application, STA typically will be fine. If you need further convincing, just create a little project (default is STA) and give it a few (say 10) threads containing a while(true) loop including (1) a for loop counting to 1 billion and (2) a Console.WriteLine(string) statement with a different string for each thread.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
Dear Mr. Pattyn,
I hope you're right, and I'll assume you are. I'm not so sure the example really proves the point, though, because there could be some scheduling or something that causes the example to look multi-threaded when in fact, the one thread's slice is actually being sliced up more or something like that. As you can probably see from my comments, it's all a mystery to me, but I'll keep the STAThreadAttribute up and contact you when it messes up.
In Christ,
Aaron Laws
http://ProCure.com
|
|
|
|
|
I'm pretty confident my take on the matter is right; I understood they invented the apartment stuff to allow multi-threaded apps to use COM components that had been designed without thread-safety in mind. Therefore STA enforces sequential access. And then they decided to make STA the default in .NET, since otherwise too many people would fall in the OpenFileDialog trap.
If you encounter clear proof otherwise, I sure want to hear from you and investigate.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
Then look at the CPU utilization, it can't go above 1 core if they're just using clever scheduling instead of true multithreading.
|
|
|
|
|
Dear Mr. Aptroot,
This is correct. I'll have to profile it that way later (when I get some clients). But I would hate to develop the application, then figure out I'm only getting one thread later and have to restructure!! That's why I wanted to know now.
In Christ,
Aaron Laws
http://ProCure.com
|
|
|
|
|
that is why I suggested you run a little test, such as:
public void Runner(object dummy) {
string text=dummy as string;
for(;;) {
for(int i=0; i<1000000000; i++) {}
Console.WriteLine(text);
}
}
Create a Console App, have it create N background threads executing Runner, each with a different text argument, and watch Task Manager
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
Your explanations sounds like STA is a per-project setting. It's not. It's actually a per-thread setting, and the attribute on void Main just controls the setting for the main thread.
You can have both STA threads and MTA threads in the same application. And yes, you can have multiple STAs running concurrently.
COM objects living in a STA have all their calls executed on the thread associated with that STA (calls are marshaled to that thread and executed sequentially).
COM objects living in a MTA have their calls executed by any MTA thread, so there can be many calls running concurrently.
Of course, all this is revelant only for threads that create COM objects. Some Windows Forms controls require the GUI thread to be in a STA, but apart from that, threading apartement doesn't matter for a pure .NET application.
|
|
|
|
|
Thanks for clarifying that. I have known this, but it faded away a bit, and that fact confirms your final statement, it not being very relevant for a pure .NET application, which is what I do most of the time.
I do recall threads could choose their STA/MTA inclination, but only once. What isn't clear to me (I should look it up actually) is the consequences of the STA/MTA choice made on static Main(); does that only affect the main thread, or does it set the default for all threads?
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
Mr. Pattyn,
My experience thus far has been that the main method only sets the initial thread's apartment model, not the default for future threads.
In Christ,
Aaron Laws
http://ProCure.com
|
|
|
|
|
Dear Mr. Grunwald,
Thanks for the explanation. That's right, I was thinking of it as a program setting, not a thread setting. So, one thing interests me (to hijack my own thread...heh), that is,
``calls are marshaled to that thread..."
This confuses me. So, perhaps a thread coming into COM looking to get something done (open a OpenFile Dialog or something) comes in, COM looks at him and decides he's STA. So, does COM hijack that thread or create a new thread? How can COM marshal calls on a thread that it doesn't own? Or, is this always done in a message pump? Perhaps you could point me to an article on this.
Your answer is excellent, rating 5. Thanks.
In Christ,
Aaron Laws
http://ProCure.com
|
|
|
|
|
Welcome everyone
Have a big problem in the end this code
This code works with one of the chat games networks
But it does not appear the Arabic letters
But appear in this form
????????????
While the characters appear as English is
How can I deal with this situation
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Threading;
using System.Text;
using System.IO;
namespace ConquerSx.PacketHandling
{
public class Chat
{
public static void Handle(Main.GameClient GC, byte[] Data)
{
MemoryStream MS = new MemoryStream(Data);
BinaryReader BR = new BinaryReader(MS);
BR.ReadBytes(8);
ushort ChatType = (ushort)BR.ReadUInt32();
BR.ReadBytes(13);
string From = Encoding.ASCII.GetString(BR.ReadBytes(BR.ReadByte()));
string To = Encoding.ASCII.GetString(BR.ReadBytes(BR.ReadByte()));
BR.ReadByte();
string Message = Encoding.ASCII.GetString(BR.ReadBytes(BR.ReadByte()));
BR.Close();
MS.Close();
#region BadWords
Message = Message.Replace("http:/", "****");
Message = Message.Replace(".net", "****");
Message = Message.Replace(".com", "****");
Message = Message.Replace(".tk", "****");
Message = Message.Replace("www", "****");
Message = Message.Replace("damn", "****");
Message = Message.Replace("f***", "****");
Message = Message.Replace("sh*t", "****");
Message = Message.Replace("stupid", "******");
Message = Message.Replace("wtf", "***");
Message = Message.Replace("idiot", "*****");
Message = Message.Replace("f***er", "******");
#endregion
modified on Friday, June 11, 2010 9:26 PM
|
|
|
|
|
There is far too much code posted here and it is not properly formatted to be readable. Please read How-to-get-an-answer-to-your-question[^], then go back and edit your question to format your code properly and also remove all the sections not relevant to your question.
It's time for a new signature.
|
|
|
|
|
I seriously doubt that anyone has got the time to wade through all of that code. Might I suggest that you cut it down to only display the important parts. Anyone that is curious enough may ask for more. In any case your question is not clear: try to rephrase it.
me, me, me
"The dinosaurs became extinct because they didn't have a space program. And if we become extinct because we don't have a space program, it'll serve us right!"
Larry Niven
nils illegitimus carborundum
|
|
|
|
|
Please do not post whole code and read
this[^] post before you ask any question.
Put your code in proper format using code block
functionality of code project.
HTH
Jinal Desai - LIVE
Experience is mother of sage....
|
|
|
|
|