|
Hi,
Are these two separate problems? Please provide some more info.
You might want to show some code (not all of it, just what you deem relevant).
For the last part: how many elements are there in the string array? what is the expected total length after concatenation?
And do you really need the concatenated string? what is going to happen to it? there may be alternatives that are more economical.
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
|
|
|
|
|
yes separate.
what is the best method? I need to do it to send it somewhere...
|
|
|
|
|
Great. You wrote code that bombs and throw a couple of exceptions. Without seeing the code that generated those exceptions, it's pretty much impossible to tell you where you went wrong.
|
|
|
|
|
here is the invoke code:
<code>
private delegate void SetTextCallback(string text);
SetTextCallback d = new SetTextCallback(SetStatusText);
this.Invoke(d, new object[] { msg });
and for the text the concatenation of strings is with the "+".
|
|
|
|
|
Well that is next to useless.
Where is the code for SetStatusText ?
What is the value of msg ?
One of the Exceptions referred to concatenating strings, you don't think that possibly, just maybe, those strings and the code to concatenate them might be useful to anyone wishing to help you?
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
questions, questions, and more questions.
All the poor chap wants is some simple answers; how difficult can it be.
Please finish your iced coffee and get him out of his misery.
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
|
|
|
|
|
Are you enjoying an iced coffee too?
I cannot give him any sort of answer, much though I'd like to.
I assume that you are composing your answers whilst I am writing this?
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
No I am not a coffee man.
Me composing while you write? No. I'm actually spending quite some time at the Euler project[^] lately. Their questions are somewhat hard however they are very clear and complete, quite a change.
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
|
|
|
|
|
Luc Pattyn wrote: Their questions are somewhat hard however they are very clear and complete, quite a change.
They do make a change from these forums, don't they.
I do looked at the site from time to time, but quite honestly the questions are far beyond my abilities. Except for the odd one or two where I can see a brute force solution.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
qwerty53 wrote: any thoughts?
* Just because the exception is thown there doesn't mean the problem is there - but usually it is anyway.
* String concatenation is "dangerous" for memory usage, I would definitely check that to make sure you aren't somehow making a string of millions of characters long.
* I have a feeling that you're concatting strings in the delegate that you pass to Invoke but that's just a feeling..
Just thoughts, that's where you asked for anyway. But unless you answer some of the questions asked by other, you're not likely to get much more than thoughts and insults.
|
|
|
|
|
Hello,
I am trying to create a RangeColumn chart in Visual Studio 2008 with C#. All of my data is being brought in through a DB and is fairly simple.
I have two columns, a category and a value.
I want the first category to be displayed normally with y= 0 and then go to y= 200. Then I want the second category to start at y=200 then go to y=300, so basically it would not be starting at zero anymore. Ive heard this referred to as a waterfall chart, but not entirely sure.
I do not how to do this with just two columns of data. Do I need to create a query that does all of the math or is there a way do to this through the properties in MSChart?
Data
Category | | Total | Device | | 38111 | Plant | | 6063 | Improvement | | 2266 |
ex
DEVICES: x=0, y1= 0, y2= 38111
PLANT: x=1, y1= 38111, y2 = 44174
IMPROVEMENTS: x=2, y1= 44174, y2 = 46440
I have been making all of the charts entirely through the design mode of Visual Studio 2008, and have not played with the code at all.
I would be forever indebt to you if you could help out. Thanks!
JM
modified on Thursday, July 2, 2009 1:45 PM
|
|
|
|
|
i want to do one project in AForge.Net. my project is when a person infront of the web cam, it should capture the image and identify the eye part only. then when that person close his eye it should says a message eye closed. please help me as soon as possible.
thank u soo much
|
|
|
|
|
See points: 1, 2, 3, 4 and 9 in this post[^]
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
jeyaluxmy wrote: please help me as soon as possible.
I think you are looking for this site[^]
|
|
|
|
|
Well, you ain't never caught a rabbit, and you ain't no friend of mine.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
|
Hi all,
I am trying to invoke the forms main thread from a worker thred, but I am desperately trying to avoid Control.InvokeRequired. To better explain, here is the code:
Simple class: (MyClass.cs)
public class MyClass
{
public delegate void LiveStatsLoginRequest(object sender, LiveStatsLoginEventArgs e);
public event LiveStatsLoginRequest OnLSLoginRequest;
public MyClass()
{
}
public void OpenConnection(string postData)
{
var args = new object[] {postData, Operation.Check, LiveStatsAction.Authenticate};
var t = new Thread(dowork);
t.Start(args);
}
private void dowork(object args)
{
DoSomethingThatTakesALongTime();
OnLSLoginRequest.Invoke(this, new EventArgs());
}
}
Now the main form (MainForm.cs)
public partial class MainForm : Form
{
private MyClass myClass;
public MainForm()
{
InitializeComponent();
myClass = new MyClass();
MyClass.OnLSLoginRequest += LiveStats_OnLSLoginRequest;
}
private void Form_Load(object sender, EventArgs e)
{
myClass.OpenConnection(new object[]{"Something"};
}
private void LiveStats_OnLSLoginRequest(object sender, LiveStatsLoginEventArgs e)
{
this.TextBox1.Text = "Logged in!";
}
}
The problem is that I get an error due to cross threading. I know that I can fix this my doing the following:
MainForm.cs
private void LiveStats_OnLSLoginRequest(object sender, LiveStatsLoginEventArgs e)
{
if (InvokeRequired)
{
}
else
{
this.TextBox1.Text = "Logged in!";
}
}
But I think this is messy and I would like to do the invoking through the class itself. I will eventually be releasing this code open source and don't want the user to have to worry/need to invoke the main form.
How can I solve this?
many thanks
(Sorry for the crude code!)
|
|
|
|
|
Take a look at Avoiding InvokeRequired[^] and see if that helps.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
The spell clearly didn't work in my favor, now you're beating me in answering C# questions
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
modified on Thursday, July 2, 2009 1:03 PM
|
|
|
|
|
How does it go?
Zut alors!
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Hi,
Control.InvokeRequired is the correct way to deal with this.
You can hide it in a helper class, that is what Avoiding InvokeRequired[^] (a very recent article here on CP) does for you, however I'd rather use code that works straight with InvokeRequired.
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
|
|
|
|
|
Luc Pattyn wrote:
You can hide it in a helper class, that is what Avoiding InvokeRequired[^] (a very recent article here on CP) does for you, however I'd rather use code that works straight with InvokeRequired.
Hmm I see what you mean (i sorta missed what you said when i first read your post). I read this article and have spent the last couple of hours playing with the demo. It really does just move the problem. May be better tools for this problem should be added to .NET 4.0 (hell its bloated anyway).
I dont know if its the intense heat (some 30C here in the UK), the fact that I am tired, or the fact that I'm watching family guy marathon on DVD, but ive taken the easy way out.
First in MyClass.cs I have added the following property:
public Form Sender { get; set; }
now when a method is called, just before an event is raised, the sender form is checked for InvokeRequired.
if (Sender.InvokeRequired)
{
var dataDelegate = new Data(LiveStats_OnData);
Sender.Invoke(dataDelegate, new object[]{sender,e});
}
else
{
}
the horrible nasty InvokeRequired is now tucked away and abstract so the user never sees it.
Bailed. Please Microsoft, give us a break.
|
|
|
|
|
Hi,
I'm not convinced you need to go for all that sender trouble: when all Controls got created by the main thread (that's the safest way to do WinForms) then whatever Control you ask for InvokeRequired will return the same value: false on the main thread, true otherwise. So a single Form or Control is all you need (and then you could also use the context stuff, which I haven't used yet).
PS: it's the same 30C in B.
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
|
|
|
|
|
Hi,
The System.ComponentModel.BackgroundWorker class raises it’s events on UI thread and would suit your requirements as you only require a task completed event.
In general terms it is possible to arrange for an event to be raised on the UI thread through use of either the Post or Send methods of the SynchronizationContext class or alternatively the Post method of the AsyncOperation class.
I’ve pasted in an example class that shows one way of doing this.
Alan.
using System;
using System.ComponentModel;
using System.Threading;
public class BackGroundTask {
private SynchronizationContext context;
public event EventHandler<AsyncCompletedEventArgs> Completed;
public void RunAsync(Object args) {
this.context = AsyncOperationManager.SynchronizationContext;
ThreadPool.QueueUserWorkItem(new WaitCallback(this.ThreadProc), args);
}
private void ThreadProc(Object args) {
Exception exc = null;
Boolean cancelled = false;
try {
} catch (Exception e) {
exc = e;
} finally {
this.OnCompleted(exc, cancelled, null);
this.context = null;
}
}
private void OnCompleted(Exception e, Boolean cancelled, Object state) {
this.context.Post(
delegate {
EventHandler<AsyncCompletedEventArgs> handler = this.Completed;
if (handler != null) {
AsyncCompletedEventArgs args = new AsyncCompletedEventArgs(e, cancelled, state);
handler(this, args);
}
},
null);
}
}
|
|
|
|
|
I love the way these pages look. How you have a list of all the posts, can click on one, and the whole post is displayed. I am in the process of doing something similar. I'm building a website that will show 5 of say 17 fields from a selected record in GridView kind of like to get the user's attention. Then, when the user clicks any of the 5 fields, all 17 fields would drop down, much like this page. Can that be done only with GridView or would I have to add a View/MultiView to the page. If I can do it with GridView is there a property I can set or would I have to write custom code? Are there any good code snippets out there?
THanks.
|
|
|
|