|
No, it is 4 columns instead 3 and now 3 rows with information
|
|
|
|
|
No, the first program was 4 rows with 3 columns now I need 4 columns with 3 rows.
|
|
|
|
|
This[^] may well be what you want.
Luc Pattyn
Have a look at my entry for the lean-and-mean competition; please provide comments, feedback, discussion, and don’t forget to vote for it! Thank you.
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
I see in near every example using threads that the method to execute in the starting of the threads belong to a different class
example: ThreadStart TH = new ThreadStart(Animal1.CuentaAnimales);
Thread Thread1 = new Thread(TH);
And it suggest to me some questions, please tell me if i´m correct or not.
1) Every Thread must include it´s own data an methods so it creates an object for keeping all the code isolates in it´s own space.
2) One Tread cann´t use methods or data created in other Threads.
3) How can I Share one object like a List or Dictionary between different threads.
Best Regards
|
|
|
|
|
1 - no, but if you have multiple threads that all access the same data, make sure you lock it to stop race conditions
2 - not so
3 - just declare it, and access it. Use the lock keyword to make sure each thread waits it's turn.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
About synchronization I see that all the synchronization tools like Lock, Monitor, Mutex need an object like parameter, but I dont know which object I need to introduce for synchronizing a method in the same class in such case I don`t understand to use Lock(this) or Monitor(this), I`m not sinchronizing all the class but only a method.
Thanks
|
|
|
|
|
Most code I've seen does something like
static object synch = new object();
and then just uses that.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
FJJCENTU wrote: I see in near every example using threads that the method to execute in the starting of the threads belong to a different class
Its all personal preferences. I never seen such a code so far though.
1) Not sure what you meant.
2) No. It can use. Make sure you are using proper synchronization mechanisms.
3) Declare it in such a way that it is accessible to both threads. See the following code,
class Foo
{
List<string> strings = new List<string>();
void StartThreads()
{
Thread t1 = new Thread(Thread1Execute);
Thread t2 = new Thread(Thread2Execute);
t1.Start();
t2.Start();
}
void Thread1Execute()
{
}
void Thread2Execute()
{
}
} If your code is doing any modifications to the strings collection, you should use some synchronization mechanisms.
FJJCENTU wrote: in such case I don`t understand to use Lock(this) or Monitor(this), I`m not sinchronizing all the class but only a method.
Using lock(this) is a bad idea. You can choose any object as your locking object. When choosing a locking object, consider the following points.
- The object should not be modifiable without your knowledge. See the following code
class Foo
{
public object locker = new object();
} In this any one can modify the locker object from outside of class Foo without your knowledge. This is dangerous. - All the threads that require this object should be able to access the locker object.
Above class can be written like the below with lock .
class Foo
{
List<string> strings = new List<string>();
readonly object locker = new object();
void StartThreads()
{
Thread t1 = new Thread(Thread1Execute);
Thread t2 = new Thread(Thread2Execute);
t1.Start();
t2.Start();
}
void Thread1Execute()
{
lock(locker)
{
}
}
void Thread2Execute()
{
lock(locker)
{
}
}
} Monitor(this) won't compile. lock is a syntactic sugar which will be compiled as Monitor.Enter and Monitor.Exit .
|
|
|
|
|
Hi,
1) i think Thread can't include it's own data, but process can include the data.
so thread is 'Lightweight'.
2) i think one Thread may create other threads.
(for example, one thread for download file, and a lot of thread created by that thread for download different data in file)
3) you can use public static data to share, but you should remember to synchronous it.
modified 27-May-14 5:34am.
|
|
|
|
|
Hi all,
I have a combo box that can be several values (example: Yes/No/Neither). I want to bind the combobox possible options to a table in a database.
TableOptions
Yes
No
Neither
But lets say a user ran the application and went ahead and selected one of these options. I am storing that selection in a different table.
TableProduct
ProductID Selection
1 No
When the application loads I want it to display the chosen selection (No in this case), but still show the allowable options stored in the first table.
Is this possible?
Thanks
Marc
|
|
|
|
|
Yes. You create the controls to contain the values, then you set each row to the right value, in the item data bound event perhaps ?
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
I am not sure what you mean.
|
|
|
|
|
use
ComboBox cc = new ComboBox();
cc.DataSource = dt;
cc.DisplayMember = "xx";
cc.ValueMember = "yy";
cc.SelectedValue = "value";
Hope you can do it now.
|
|
|
|
|
All you can do is to load the data source depending on the condition you need. I mean join TableOptions and TableProduct and load all the values if no record exist else load the selected record first. Once all loaded, bind it to dropdown.
Another method is to query TableProduct after you binded all values from TableOptions . If any value exist in TableProduct, get that value and make it as selected.
|
|
|
|
|
I was hoping there was a quick and easy way to do this without much manual programming - since I have over 100 comboboxes to populate in this manner.
In VS 2008 in the graphical designer I clicked the combobox.
Why wont this work:
I specify the two data sources and bind the TableProduct to the "selected value". I bind the DisplayMember to TableOptions. However the selected value property does not seem to get set.
Thanks
Marc
|
|
|
|
|
Hi,
for example
DataTable table = new DataTable();
sqlcon = new SqlConnection(StrCon);
SqlDataAdapter ada = new SqlDataAdapter("select top 20 jsyhm,xm from zjsxx", sqlcon);
sqlcon.Open();
ada.Fill(table);
sqlcon.Close();
comboBoxEx1.DataSource = table.DefaultView;
comboBoxEx1.DisplayMember = "xm";
comboBoxEx1.ValueMember = "jsyhm";
|
|
|
|
|
Hi
I think must be doing something silly here, but cannot see it. My problem is reading in data from an XML Document into a DataSet in C#.
I have declared a Data Set and a Data Table and used the XMLReader in the Data Set to read in the XML Document - ds.XMLReader("A.xml"). However, I am unable to point the dataset to the datatable.
The dataset does read in the XML without error, and I can write it out again to a new XML Document.
Can someone show me how to point a dataset to a datatable?
Thanks
|
|
|
|
|
I assume you mean ReadXml(), not XmlReader()...
Not quite sure what you're asking here, but if you're trying to get a reference to the table you loaded, that's easy enough:
DataTable dt = ds.Tables[0];
DataTable dt = ds.Tables["MyTableName"];
|
|
|
|
|
Hi
Yes, sorry, it should be readxml.
I did try referencing the table either by index or by name, but all it said was that the table is not there or does not exist. This is what I wrote orginally:
DataSet ds = new DataSet("mySet");
DataTable dt = new DataTable("myTable");
ds.Tables.Add(dt);
ds.ReadXml("myXml");
When I read in the xml into the dataset and then wrote it out to a new xml document it does it - no error, but I can get the data to a table, where I can then work with each value.
I would have thought just a couple of lines of code was all that was needed with DataSets?
|
|
|
|
|
Don't create the table... The dataset will do that for you. Set a breakpoint right after the ReadXml, hop into the watch window, and see what's in the Tables collection... You might just be looking for the wrong table name, because it names it based on the XML file...
This is all assuming the XML file is a valid dataset dump, of course.
|
|
|
|
|
Hi,
for example
String fileName;
fileName = "users_2.xml";
Dataset myDs = new Dataset();
try
{
FileStream fin ;
fin = new FileStream(Server.MapPath("./files/"+fileName), FileMode.Open,
FileAccess.Read, FileShare.ReadWrite);
myDs.ReadXml(fin);
fin.Close();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
modified 27-May-14 5:34am.
|
|
|
|
|
I want to encrypt my source code how can this be accomplished.
|
|
|
|
|
khalil.kamel wrote: I want to encrypt my source code how can this be accomplished.
Why would you do so?
In between, there are many encrypting tools available on internet.
Manas Bhardwaj
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
I want it to be encrypted on the client side. I do not want the user to see my source for security purposes
|
|
|
|
|
Why would they be able to see your source code ? Do you mean via reflection ? You're going to have to spend some serious money to buy a tool to precompile your .NET app so you don't use MSIL.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|