|
Always wrap your code in Pre tag.
|
|
|
|
|
What does a device do when it is programmatically unplugged?
Some devices switch off - how could you plug it programmatically?
Some devices connect in a different mode to receive electricity via the USB port for charging their internal batteries (e.g. connect a "HID keyboard"). In such cases, the SDK of the manufacturer could provide a function to switch the device to its "normal" connected mode.
|
|
|
|
|
|
We have a set (~50) of local mode reports hosted in forms as plugins (dlls) in our app.
They were initially developed in VS2005 and later ported to VS2008.
We are now attempting to get them working in VS2010.
The reports use lists to iterate over a table, invoking a subreport with the ID (primary key) as a variable/parameter so that the subreport could select details from related tables and display them.
Some of the subreports used lists and sub-subreports, on and on.
However, as of VS2010, even once we get the reports building and running they don't work properly.
When we attempt to assign parameters to a subreport in the parent reports' design[er] using
Right-click ->
Subreport Properties ->
Parameters ->
Fields
Then either...
Add to create a new one or
f[unction] to edit one that's broken...
We get "Report item not linked to a dataset."
This happens even if the Field (name) appears in the "Value" combobox and we select it.
Does anyone know how to fix this or get past it...
|
|
|
|
|
hey guys!
does anybody have any experience
in C# ? i would need to read data (numbers) from
*.txt file and plot them in ZedGraph in Csharp
it is easy to make a plot of equestion
but i am suppose to plot bar graph like that:
v1 v2 v3 v4 v5
0122 4466 2847 2640 82800
0122 4466 2847 2640 82801
0122 4466 2847 2640 82802
0122 4466 2847 2640 82803
0122 4468 2847 2640 82804
0122 4468 2847 2640 82805
0122 4466 2847 2640 82806
0122 4466 2847 2640 82807
the task is easy, plot every
column seperately like bar
histogram. i have no idea
how to read data from .txt
i am a beginner and it´s
really important for me.
thx!
|
|
|
|
|
This sounds a lot like homework, so I won't give you full code!
Having said that, it's not a complex task, if you just break it down into the various parts:
1) Read data from text file
2) Convert data to numbers
3) Plot data
It's never that simple, though, because 2 and 3 will have some relationship, because ZedGraph will define what it want's in the form of data.
But the principles are the same.
1) Reading from a text file: easy!
string[] lines = File.ReadAllLines(pathToFile); That's it - all done.
2) Convert to numbers: Not too difficult.
First you need to repeat some action for each line, and convert a line into the various values to be plotted. Since your data appears to be separated by spaces, it would make sense to split teh line up on those and then convert the relevant numbers only.
Set up a foreach loop to work on each line of lines above (the info will be in your notes).
For each line, split iot on a space:
string[] parts = line.Split(' '); This gives you an array of separated values, as strings. It looks like you want to plot the second and fifth values since they are the only ones changing. So the strigns you will need to convert to numbers are parts[1] and parts[4] since C# always starts numbering at zero, not one.
To convert a numeric string to a numeber, use int.Parse:
int value = int.Parse(numericString); For example:
int value = int.Parse("123"); Would give you the number one hundred and twenty-three in the variable value
3) Put the values together, and pass them to ZedGraph.
This bit is up to you - I don't use ZedGraph and don't want to look up for you how it expects it's data - you probably have some notes giving you a short cut on that anyway!
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
i really appreciate
your advice, and
i am going to try
applying you have
just written me.
Thank you very much!
|
|
|
|
|
You're welcome - good luck!
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
Hello!
I have a question regarding an unsafe code blocks in C#. As is well known, the following code:
int[] x = new int[10];
int* ptr;
fixed (int* fix = x)
{
ptr= fix;
}
*(ptr+1) = 123;
Is bad, because ptr is outside the fixed block and the array might be moved by GC. However, is the following code bad too?
int[] x = new int[10];
GCHandle xH = GCHandle.Alloc(x);
int* ptr;
fixed (int* fix = x)
{
ptr= fix;
}
*(ptr+1) = 123;
xH.Free();
If it is wrong, what is an alternative?
Greetings - Jacek
|
|
|
|
|
You should use the overload of Alloc that takes a GCHandleType, and pass GCHandleType.Pinned.
And then using fixed as well is confusing, but there is AddrOfPinnedObject which you can cast to a pointer.
|
|
|
|
|
Thank you!
What I actually wanted to do was to take fixed statements outside a loop. It's because I have discovered, that these statements bring an overhead and, therefore, a performance drop. So, I had an idea to "cache" pinned pointers but I couldn't use a fixed statement when outside a loop. Finally, here is a result:
string[] oldValues,
int oldCount = oldValues.Length;
GCHandle[] oldHandles = new GCHandle[oldCount];
for (int i = 0; i < oldCount; i++)
{
oldHandles[i] = GCHandle.Alloc(oldValues[i], GCHandleType.Pinned);
}
char* oldFix = oldHandles[i].AddrOfPinnedObject();
fixed (char* oldFix = oldValues[i])
This brought about 1.5x performance increase, so it was worth. But still I'm not sure if it is correct (and is hard to detect experimentally due to unpredictability of GC).
Edit: fixed fixed code
Greetings - Jacek
modified 27-Dec-11 13:15pm.
|
|
|
|
|
I don't know, I'm not 100% sure of this, but it looks to be fixing the strings temporarily and not long enough.
Jacek Gajek wrote: but I couldn't use a fixed statement when outside a loop Why is this? I've written plenty of loops spanned by a fixed.
Not that many, granted, but I would say that usually when I use fixed, there is P/Invoke or a loop inside it.
edit: I would only use the GCHandle way to pin if something has to remain pinned for a long time or the pinning must survive returning from the function that pins it in a way that can not be refactored in a sane way (typically these things happen at the same time). Or in the rare case that a GCHandle is required anyway.
modified 27-Dec-11 12:49pm.
|
|
|
|
|
harold aptroot wrote: Why is this? I've written plenty of loops spanned by a fixed.
If you have a single pointer then it is possible. But if you had an array of strings A, then you cannot pull the fixed statement outside the loop since you do not have an indexer:
while(...)
for(int i = 0; i<len; i++)
{
fixed(char* str = A[i])
}
Solution:
GCHandle[] handles= new GCHandle[len];
for (int i = 0; i < len; i++)
{
handles[i] = GCHandle.Alloc(A[i], GCHandleType.Pinned);
}
while(...)
for(int i = 0; i<len; i++)
{
char* str = (char*)handles[i].AddrOfPinnedObject()
}
for (int i = 0; i < len; i++)
{
handles[i].Free();
}
Note: I use memcpy and memcmp inside, so yes there is some P/Invoke shift involved.
Greetings - Jacek
modified 27-Dec-11 13:15pm.
|
|
|
|
|
Oh ok, makes more sense now.
Why is the array pinned too though?
|
|
|
|
|
No special reason. It also caused a fatal exception. Now removed.
Greetings - Jacek
|
|
|
|
|
Sometimes I get "handle is unpinned" exception on AddrOfPinnedObject method call. Any ideas how is it possible? As I see in dotPeek, the exception is thrown because a condition ((int) this.m_handle & 1) != 0; is not satisfied. Since I do not call Free until the method's exit point, I really don't get how was it possible to happen .
Greetings - Jacek
|
|
|
|
|
I don't know, that makes no sense to me.. I would almost say it's a bug in the CLR, but those are rare so I'm probably missing something
|
|
|
|
|
Jacek Gajek wrote: 1.5x performance increase
Compared to what?
And what, exactly, are you trying to accomplish?
|
|
|
|
|
Jacek Gajek wrote: If it is wrong
Probably.
Jacek Gajek wrote: what is an alternative
Set it within the fixed block?
|
|
|
|
|
PIEBALDconsult wrote: Set it within the fixed block?
Thank you for your interest, but I though it was obvious that for some reasons I need another solution than this.
Greetings - Jacek
|
|
|
|
|
Jacek Gajek wrote: I though it was obvious
Obviously not.
|
|
|
|
|
Understanding what you are doing and what you think you are achieving would help.
For example the following might or might not be relevant.
- Allocating a block or pool of blocks at application start and using those over and over might be better than any solution that requires re-allocating over and over.
- If you haven't profiled the application under a correct production model load (not test load) then attempting to optimize anything is futile.
|
|
|
|
|
hello guys... Lets suppose I have a TextBox on this Form1. Now when I resize the form, I want the resize the textbox as well. I have been trying to do this, but have not been able to get the <b>Size</b>, <b>Height </b>or <b>Width</b> property of Form1 in <b>IntelliSense</b>. I have <code>System.Drawing</code> in my code file as well.
|
|
|
|
|
Try Anchor ing it to both sides of the Form.
|
|
|
|
|
Try TextBox1.Width TextBox1.Height or TextBox1.Dock would be better.
Frazzle the name say's it all
|
|
|
|