|
fghfghfghfgh
suresh babu.k
|
|
|
|
|
|
Do you have the HotTracking property on the ListView set to true?
Logifusion[^]
|
|
|
|
|
no i wish it was that easy
|
|
|
|
|
Hi, i have my mainform referenced in my dll proj. I am wondering how i can read a text file and send the text to a textbox on the mainform:
public static void ReadText(string source)
{
using (StreamReader sr = new StreamReader(source))
{
String file = sr.ReadLine();
}
}
Thanks alot for your help!
Don't be overcome by evil, but overcome evil with good
|
|
|
|
|
either pass the textbox as an argument, or make a method in the mainform app available as a delegate to the DLL which it can invoke when it reads the data. Define the delegate in the dllClass which I assume is referenced in your mainform a'la, also define one of these as a property with get/set accessors
"public delegate void _TextProcessor(string _theText);"
public _TextProcessor TextProcessor { get { return theTextProcessor } set { theTextProcessor = value } }
in you mainform write a method that conforms to the delegates "template" and assign it to the exposed property:
private void myTextProcessor(string _text)
{
this.textBox.Text = _text;
this.theBox.Invalidate();
}
dllClass.TextProcessor = myTextProcessor;"
replace your comment in the dllClass with something like "theTextProcessor(sr.ReadLine());"
|
|
|
|
|
Thanks!
Don't be overcome by evil, but overcome evil with good
|
|
|
|
|
Hey pjd i tested out what you gave me and i tried it out but i'm having a few problems. If you could help me out that would be great!
On the mainfrm it isn't giving me the option to add the delegate "TextSender". Once i get that i should be fine with the app part of it. What i would want to put here is textReader.TextSender = ProcessText;
public partial class mainfrm : Form
{
public mainfrm()
{
InitializeComponent();
}
private void rfButton_Click(object sender, EventArgs e)
{
OpenFileDialog open = new OpenFileDialog();
open.Title = "Select A Text File";
open.InitialDirectory = @"C:\";
open.Filter = "Supported Files|*.txt";
open.Multiselect = false;
open.ReadOnlyChecked = false;
if (open.ShowDialog() == DialogResult.OK)
{
foreach (string filename in open.FileNames)
{
textRead.ReadText(open.FileName);
}
}
}
private void ProcessText(string text)
{
textBox1.Text = text;
textBox1.Invalidate();
}
}
The compiler complains when i try to add this.TextSender(sr.ReadLine()) giving the message below. But I need to have that method static so i can call it from the mainfrm (as shown above).
public class textRead
{
public delegate void AddText(string text);
public AddText TextSender
{
get
{
return TextSender;
}
set
{
TextSender = value;
}
}
public static void ReadText(string source)
{
using (StreamReader sr = new StreamReader(source))
{
this.TextSender(sr.ReadLine());
}
}
}
Thanks again for your help!
Don't be overcome by evil, but overcome evil with good
|
|
|
|
|
I don't see where TextSender gets a value - TextSender is a property which needs storage to put its data - in textRead class, under delegate definition put " private AddText _textSender;" that'll set aside some memory for an AddText object.
in the TextSender Property get will return _textSender set will asign _textSender to value
In mainform you need to give textRead.TextSender a value, suggest you do in in constructor textRead.TextSender = ProcessText;
In ReadText suggest you invoke this._textSender
Why not use a handle "because the whip fell off the handle and the wheel went in a rut"
c'ya pjd;)
|
|
|
|
|
Thanks pjd for your help
Don't be overcome by evil, but overcome evil with good
|
|
|
|
|
This may sound oldfashioned ...
Use a handle ...
Don't you also love the code?
|
|
|
|
|
Hi,
I'm studing VS 2005 C# XPRESS Ed. and I'm facing with reporting. It seems Crystal Report isn't available for VS XPRESS Ed., is it? Can someone help me? I need to import some library into my c# prj (CrystalDecisions.*) but I don't know how to provide them...
Thanks in advance
|
|
|
|
|
*shameless self-plug*
See sig
----------------------------
Be excellent to each other
EasiReports[^] My free reporting component for WinForms.
|
|
|
|
|
Good Afternoon,
I've kinda hit a brickwall today with something I thought would be pretty straight forward. I have a form that loads after checking user's login credentials. I have all the "processing" functions in an independant class that I use often in other projects. The objects on the form are set to public. I understand that a c# form is a class so I thought the following would work but I can't seem to get access to manipulate the objects on the form.
DataGridView dgCallMonitor = (DataGridView)frmOpsCon.ActiveForm.Controls["dgCallMonitor"];
Any help or pointer to what I'm doing wrong would be appreciated
JB
|
|
|
|
|
What I usually do in a case like that is make a public property on the form in question exposing the control then I can just access it through the property.
|
|
|
|
|
An alternative to exposing the form controls to the "processing" class, which would encumber it with the overheads of Windows.Forms etc, is to use delegate methods. See my post to the nearby question from teejayem titled "Dll question". I've used this method in classes that are used in three environments gui, command line and server, works well.
cheers phild
|
|
|
|
|
Hello,
Is it necessary to ensure thread-safety for an instance of the System.String class? I understand that String s are immutable types, but I was unsure if this necessarily means that an instance of the System.String class is thread-safe for multiple readers and multiple writers.
In my application, several String s which belong to an instance of a class will be both accessed and changed from multiple threads. I can easily put a lock on them and make sure the operations do not clash, but if I do not have to waste time waiting for the lock because the type is naturally thread-safe then of course I do not want to.
I understand that this may be a simple question, but for some reason I cannot find a clear universal answer to the question.
Thanks in advance!
Sincerely,
Alexander Wiseman
|
|
|
|
|
They are not threadsafe by default. Only static variables are automatically threadsafe.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Thanks for your reply. I am still confused, however, because in the MSDN documentation, it says this about a System.String (and it makes no distinction between static members and instance members):
Quote from MSDN System.String Overview
Thread Safety
This type is safe for multithreaded operations.
End quote from MSDN
Furthermore, just because a variable is declared to be static does not mean that it is thread safe. I was under the impression that the programmer had to make sure that variables, even static ones, were thread safe.
That being said, my original confusion remains, because it seems like, from the MSDN documentation, there is nothing required on the part of the user of the System.String class to ensure thread safety. What little I have read concerning "immutability" of the string type would support this. On the other hand, if I am doing multiple write operations and multiple read operations, is there going to be a problem?
Thanks again.
Sincerely,
Alexander Wiseman
|
|
|
|
|
Alexander Wiseman wrote: That being said, my original confusion remains, because it seems like, from the MSDN documentation, there is nothing required on the part of the user of the System.String class to ensure thread safety. What little I have read concerning "immutability" of the string type would support this. On the other hand, if I am doing multiple write operations and multiple read operations, is there going to be a problem?
Since strings are immutable, they are thread safe. What happens when you perform a write operation on a string is that a new string is created as a result; the original string remains unchanged.
|
|
|
|
|
Thanks for your reply.
Let me just make sure I have this clear with a quick example. Let us say that I have two threads, A and B, both of which have access to String someStr = "My String" .
Now let's say that the processor gives a time-slice to thread A, which then reads the string. Then the processor gives a time-slice to thread B, which then changes the string from "My String" to "Your String".
If I understand you correctly, then because strings are immutable, no matter when the processor decides to temporarily stop processing on thread A, nevertheless thread A will still see the value "My String", even though thread B may have "changed" it already. Is that correct?
Thanks again for your help!
Sincerely,
Alexander Wiseman
-- modified at 17:48 Tuesday 13th June, 2006
[EDIT]
Just read another poster's reply, which answers this scenario in the affirmative.
[/EDIT]
|
|
|
|
|
Alexander Wiseman wrote: Let me just make sure I have this clear with a quick example. Let us say that I have two threads, A and B, both of which have access to String someStr = "My String".
Now let's say that the processor gives a time-slice to thread A, which then reads the string. Then the processor gives a time-slice to thread B, which then changes the string from "My String" to "Your String".
If I understand you correctly, then because strings are immutable, no matter when the processor decides to temporarily stop processing on thread A, nevertheless thread A will still see the value "My String", even though thread B may have "changed" it already. Is that correct?
What you're doing here isn't changing the string. You are changing the reference to the string. When you do this:
string someString = "My String";
And then do this:
someString = "Your String";
You've taken the reference to "My String" and changed it to point (sorry for the C++ nomenclature) to "Your String";
That's not the same as actually changing the string. And as far as I know, changing what a reference, erm, references is not an intrinsically thread safe operation, but I could be wrong.
Changing the actual string would be doing something like this:
string someString = "My String";
someString.Concatenate(" and Your String");
Console.WriteLine(someString);
Now, the above code isn't possible with an immutable string. Rather the operation for concatenating a string creates a new string:
string someString = "My String";
string anotherString = someString.Concatenate(" and Your String");
Console.WriteLine(someString);
Console.WriteLine(anotherString);
Again, I'm not sure if the string class actually has a "Concatenate" method, but the principle is the same. When doing a write operation on a string, a new string is created as a result leaving the original unchanged.
[EDIT]Apparently, changing what an object references is an atomic operation, so it is thread safe.[/EDIT]
-- modified at 18:00 Tuesday 13th June, 2006
|
|
|
|
|
Alexander Wiseman wrote: In my application, several Strings which belong to an instance of a class will be both accessed and changed from multiple threads. I can easily put a lock on them and make sure the operations do not clash, but if I do not have to waste time waiting for the lock because the type is naturally thread-safe then of course I do not want to.
When you say that the strings belong to an instance of a class and are accessed and changed, are you talking about string properties?
-- modified at 17:44 Tuesday 13th June, 2006
|
|
|
|
|
Thanks for your help, Leslie. Actually I think the question was simpler than that - Guffa's post below answers it.
Sincerely,
Alexander Wiseman
|
|
|
|
|
As strings are immutable, you can't change a string. What happens when you assign a new value to a string variable, is that the new value is a separate string object, and the reference to that object replaces the reference to the previous value.
As reading and writing references are atomic, there is no need to use a lock.
When you read the string value, you are copying the reference to the string. You can then use that reference to access the string that was the value at the moment you read the reference, without fear of anything happening to that string.
---
b { font-weight: normal; }
|
|
|
|