|
A "better" way of doing this would to use the ReadWriterLock, allowing multiple readers but single writers. And yeah, you'll need to implement all the methods yourself.
The problem with the built in .Synchronized versions of Hashtable and ArrayList is that naive developers assumed that you could create a synchronized version of the list, have one thread insert an item in the list, and have another thread iterate over it using foreach. BAD PRACTICE! Because using a foreach will iterate over the list without locking it (it can't lock it because it doesn't know when the consumer is done iterating over it). So the insert on another thread interrupts and foreach, causing an exception because the list can't be modified while iterating over the list with foreach.
In other words, you can't just assume a synchronized version of your list does takes care of all threading issues. The consumers of the list have to ensure proper synchronization.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Homosexuality in Christianity
Judah Himango
|
|
|
|
|
Thanks for suggesting ReaderWriterLock, I already looked into it before and it seemed what I wanted, but using lock was just easier.
I also knew about iteration problem, but I do not worry about that as I only need to insert and get data back.
|
|
|
|
|
Okay, I have had no luck and somehow I know this should be easy. I made an app that receives data and processes the info and does calculations, etc. But I can't get the data to write to anything on the form. I know how to use form button and such, but I want the app itself to write to a textbox, datagrid, whatever on the form. But I can't get it to work. Any help is greatly appreciated. I'm using Visual C# .Net. I can only get it to write to the console. HELP!
Thanks,
RABB17
|
|
|
|
|
That greatly depends on what Control you want to fill.
Moste controls (like TextBox, Label, GroupBox...) have a Text property where you can set a string to determine which Text is shown, e.g.:
myTextBox.Text = myCalculatedNumber.ToString();
To fill the DataGrid is a bit more complicated. You will have to create a DataTable, add columns to it, fill the rows and finally set the DataSource property of the DataGrid to this object:
DataTable dt = new DataTable();
dt.Columns.Add("First Column", typeof(int));
dt.Columns.Add("Second Column", typeof(string));
dt.Rows.Add(new object[] { 1, "First Row" };
dt.Rows.Add(new object[] { 2, "Second Row" };
dt.Rows.Add(new object[] { 3, "Third Row" };
myDataGrid.DataSource = dt;
|
|
|
|
|
String [] str = new String [8];
str[0] = "a1";
str[1] = "b1";
str[2] = "c1";
str[3] = "d1";
str[4] = "e1";
str[5] = "f1";
str[6] = "g1";
str[7] = "h1";
then i want to take input
for(int i = 0; i < 8 ; i++)
{
input = Console.ReadLine()
source1=str[i].CompareTo(input);
Console.WriteLine(source1);
if(source1 != 0)
{
Console.WriteLine("no");
Console.WriteLine(i);
}
else
{
Console.WriteLine("yes");
Console.WriteLine(i);
temp3 = i;
i = 9;
}
i always say no if i take input within the loop. and work correctly if i take input out of loop. but i want untill user give correct input it takes input again and again. how i will do this .
|
|
|
|
|
How the crap do I put a parenthesis in a string in C#???
I want to do this... string asdf="(";
/\ |_ E X E GG
|
|
|
|
|
Why not try before you ask? That is exactly how you do it. There is nothing special about having a paranthesis in a string. It's just like any other character.
---
b { font-weight: normal; }
|
|
|
|
|
how about in java?
/\ |_ E X E GG
|
|
|
|
|
String asdf = "(";
Same escape sequence rules in C, C++, C#, and Java.
|
|
|
|
|
Must be something else you are doing. That should work.
The only tricky character is the backslash. It is the escape character for non-printing and control characters, so you have strange constructions like:
string abcd = "\"\\\"";
That translates to a string containing double-quote backslash double-quote.
|
|
|
|
|
I'm trying to create a launcher program that will automatically update files for another program and then launch that updated program. The launcher and the main app have already been created as seperate VS .Net projects(.exe). My question is would it be possible to build the main app as a dll, reference it in the other project and then have the launcher update the dll and launch it? Any sort of help would be greatly appreciated.
Code first, ask questions later.
|
|
|
|
|
|
Hm. This provides the same sort of functionality I'm looking for, but since I've already wrote the auto-updater I'm just wondering if there is an easy way to integrate two projects so one can open the other. Both are .exes right now, I would like the internal problem to be a .dll.
|
|
|
|
|
What you want to do is called "late binding". Search on that term and you will find several articles.
|
|
|
|
|
Hello,
Is there a way of making a specific cell in the column of a Grid - ReadOnly.
Thank you.
|
|
|
|
|
Short answer: No.
Long answer: Uhmmm... well... yes. But its a bit complicated:
You will have to inherit from the DataGridTextBoxColumn and override the Edit function. Here you could throw an event with CancelEventArgs, catch it somewhere outside and determine from the CurrentCell whether it should be ReadOnly or not (and set the Cancel of the EventArgs).
|
|
|
|
|
Hello,
Is there a way to implement a div operation on two numbers?
I need the quotent result.
So if I have two decimals, and my result after division is 5.2, I need only 5.
Thank you
|
|
|
|
|
|
Thank you.
By the way, do you know how to format the decimal output to only 4 decimal points?
If I have:
decimal totalArea = (NetRes * DevRes);
how do I format totalArea to have 4 decimal points?
Thank you.
|
|
|
|
|
You don't format totalArea to 4 decimal digits. You could round it to 4 decimal digits, which is a bit different:
totalArea = Math.Round(totalArea, 4); Here you are changing the number itself. Also, you can convert to string with 4 decimal digits:
string area = totalArea.ToString("0000"); This last statement will fill area with the string representation of totalArea , with 4 decimal places. totalArea won't be modified and will keep all its digits.
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
Thak you.
Luis, wanted to ask you one more question.
I have a dataview on a Table, and I apply a RowFilter on it:
dataview.RowFilter = "TimelineID IS NULL";
If I output the dataview.Count, it equals 2. So, do you know how I can access these rows in dataview? I don't want to use dataview.Table.Rows, becuase it returns all the rows in the dataview.
Thank you
and sorry to bother you with so many questions
|
|
|
|
|
<code>foreach(DataRowView row in dataview)
{
int x = (int) row["x"];
} or you could also:
int x = (int) dataview[rowIndex]["x"]; zaboboa wrote:
Thank you
and sorry to bother you with so many questions
Don't worry, I'm here to help! You're very welcome!
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
i have a program, that scan files in a directory .
i need to know, if is the file open or in edit mode, or if it Changes the size.
Is there any way to do that, any method like IsOpen?
|
|
|
|
|
I think you could simulate it. Try to open it, if it works, then it isn't open otherwise it's close.
Niklas Ulvinge aka IDK
|
|
|
|
|
Did anyone has seen a C program that fixes JPEG header files? I've saw it before and unfortunately haven't had time to copy it down. I would love to compile it and run it. Any tips in tracking position before pointer and after pointer would also help, I've always thought it was *+1 or *-1 Thanks!
|
|
|
|