|
This exact line of code is where the error occurs:
ThreadStart Wfrequency = new ThreadStart(cacophony.Beeper((int)nw, Duration, 16383));
Specifically the ThreadStart() function.
The error is:
Method name expected.
|
|
|
|
|
As shown on the link that Peter already gave you, the delegate creator needs the method name only. So your code should be:
ThreadStart Wfrequency = new ThreadStart(cacophony.Beeper);
See also Creating Threads and Passing Data at Start Time[^].
|
|
|
|
|
Ok, but as you may see. The Beeper(); Function inputs 3 parameters (frequency, Duration and volume).
The
ThreadStart(cacophony.Beeper); does not pass these parameters or am I missing something?
|
|
|
|
|
Member 12244972 wrote: or am I missing something? Yes, what you are creating here is a delegate, not an immediate call to the beeper method. You need to spend more time reading the links you have been given to understand how delegates are used. See the tutorials on Events and Delegates at C# Tutorials (C#)[^].
|
|
|
|
|
Ok, removed the
ThreadStart();
and implemented a lambda...
Thread childThreadW = new Thread(unused => cacophony.Beeper((int)nw, Duration, 16383));
and my code builds fine now.
Thank you all!
|
|
|
|
|
|
"don't work" is very vague. What exactly does that mean? What line of code? Any error messages? Do you have the library required to read these files?
|
|
|
|
|
While I'm generally in favor of Controls letting the user do anything ... and, then, pay the price for doing something stupid, I'm just curious if the WPF and ASP.NET Controls allow the same.
I have a bright student who keeps asking me why they can create multiple nodes whose text (what appears on the Node Label) is identical; I tell them: "you think that's crazy: how about an entire TreeView where every Node has both identical Text and Name (Key) values ?" Then, I show them how to create a sub-classed TreeView that prevents identical Text, or Name (Key) values.
thanks, Bill
«There is a spectrum, from "clearly desirable behaviour," to "possibly dodgy behavior that still makes some sense," to "clearly undesirable behavior." We try to make the latter into warnings or, better, errors. But stuff that is in the middle category you don’t want to restrict unless there is a clear way to work around it.» Eric Lippert, May 14, 2008
|
|
|
|
|
BillWoodruff wrote: I have a bright student who keeps asking me why they can create multiple nodes whose text (what appears on the Node Label) is identical ..because that would be a limitation that does not bring us much in return, but it would be easy to prevent loading duplicates yourself.
I agree that the user should be able to uniquely identify an item before interacting with it; a identity-column should not be visible and is not enough for a user to distinguish between items - so, how do you convey that there are three fields in your view that make an item unique?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I love the treenode object I scrounged from one of Josh Smiths articles, tag property as an object and shove the underlying object for the node into there.
Extend it with a few properties and you can support a treelistview.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hi,
I'm trying to use the SendMessage for sending memory stream. I did some code, but not working. Here's my code.
stream.Seek(0, SeekOrigin.Begin);
int dataSize = Convert.ToInt32(stream.Length);
byte[] byteArray = new byte[dataSize];
int count = stream.Read(byteArray, 0, 20);
while(count < stream.Length)
{
byteArray[count++] = Convert.ToByte(stream.ReadByte());
}
IntPtr ptrData = Marshal.AllocCoTaskMem(dataSize);
Marshal.Copy(byteArray, 0, ptrData, dataSize);
CopyDataStruct cds = new CopyDataStruct
{
cbData = dataSize,
dwData = (IntPtr)1,
lpData = ptrData
};
SendMessage(hWnd, WM_COPYDATA, 0, cds);
Thanks
|
|
|
|
|
|
Could I know which line you are pointing to, please?
|
|
|
|
|
The CopyStruct parameters have the length set as 1, but I think it needs to be the length of the data. The documentation is unfortunately not very clear, so I suggest you try a few different things.
[edit]
Looking again, you have cbData and dwData in the wrong order.
[/edit]
|
|
|
|
|
You mean this?
cds.dwData = dataSize;
cds.cbData = (IntPtr)1;
|
|
|
|
|
Have you tried it, and did it work?
|
|
|
|
|
That didn't work. dwData should be (IntPtr)copyDataType which worked.
Thanks
|
|
|
|
|
HI,
My question is,What is Stack and Heap in C#???
As i search in net also,but i didn't understand it clearly?
So,can anyone explain me with simple example?
Thanks...
|
|
|
|
|
|
Not really, no... it's a complicated subject.
The first thing you need to get sorted is the difference between a variable, a reference, and an instance - because without that, none of the rest of this will make any sense.
An instance is an example of a class. Thinking about cars, an instance is a car you can physically get into and drive - it is distinct from all other cars in that it will have a different registration / licence number, may be a different colour, may have a different owner. Each physical car is a different instance of a generic subject "A Car".
A reference is a "pointer" to an instance: "my car" is a reference to a physical vehicle, "your car" is a reference to a different one. "This car" could refer to the same vehicle as "my car" now, and to "your car" in a moment as we physically move from one to another. Clearly, you can have many references to the same instance!
A variable is a named "place" that holds a value - this could be a number like 12 or 14, or a reference to an instance.
So when we say:
Car myCar = new Car("Mercedes", "A160", Color.Red); We declare a variable called myCar which holds a reference to an instance which is created via the new keyword.
A variable doesn't have to hold a reference : it can hold a value instead:
int i = 666; We create a variable called i which contains the value 666
This is important, because we have different names for each type of variable: we call the first one a reference type and the second a value type and how they behave is different.
-- We'll get to stack and heap soon, honest! --
When you copy a variable, it's important to know if it's a reference type or value type, because they seem to behave very differently:
int i = 666;
int j = i;
i = i + 1;
Console.WriteLine("{0}:{1}", i, j); You expect to get "667:666" because if you didn't, then doing any kind of math would get very difficult!
And you do: i and j are value types, so the value in i is copied into j, and then incremented - that doesn't affect the value in j because it's a copy of the value. If you think about variables as "pockets" it makes sense: you have five pennies in your right trouser pocket, and you copy the value to your left trouser pocket - you now have five coins in each pocket. Adding a coin to the right pocket doesn't affect the number of coins in the left (unfortunately).
When you do this with reference types it seems to work very differently:
MyClass a = new MyClass();
a.Value = 666;
MyClass b = a;
a.Value = a.Value + 1;
Console.WriteLine("{0}:{1}", a.Value, b.Value); This time we get "667:667" because the reference in a is copied to b and so both variables reference the same instance.
-- Stack and heap coming up - very soon now --
It looks like they are doing totally different things, but they aren't, not really - the assignment is doing the same thing in both cases: it's copying the value in one variable to the other variable. It's just that the effects are different because in the first case it copies the value and in the second it copies the reference .
And if any of that make sense, we can now get around to the stack and the heap!
The heap is a big "lump" of memory which is sorted out by the Garbage collector and all classes, methods and threads in your application share it. The stack on the other hand is specific to a thread, and everything on the stack is discarded when you exit the method.
That doesn't mean a lot, does it?
Let's try starting by using them both.
private MyClass MyMethod(MyOtherClass parameter)
{
int i = parameter.Index;
MyClass mc = new MyClass();
mc.Name = parameter.UserName;
mc.ID = i + 1;
return mc;
}
When you call it, this uses quite a few bits of memory:
1) The stack gets the return address of the method - so it knows where to go back to.
2) The stack gets a copy of the reference to the parameter (the actual class instance is on the heap already)
3) The stack gets an integer called i (which is given a copy of the Index value from the parameter)
4) The stack gets a variable called mc (which can hold a reference to a MyClass instance)
5) The heap constructs an new instance of MyClass and the reference to it is copied to mc
6) The parameter reference is used to identify the instance of MyOtherClass you passed into the method, and it's UserName property is copied to the MyClass instance Name property. This copies a reference to the property and UserName and Name are both reference types.
7) The value in i is fetched, incremented by one, and is copied to the MyClass instance ID property.
8) The reference to the instance of MyClass it returned to the outside world.
9 The method ends, so the stack is reset to the state it was in when the method started - which releases the space occupied by both the i and mc variables - and the return address is fetched from the stack so the method knows where to go back to.
At this point, i and mc no longer exist - they have gone out of scope and the space for them has be recycled. But... the instance of MyClass that mc referred to hasn't - it is on the heap and will only ever be released and recycled by the Garbage Collector. Which means that the mc variable is lost, but the data it references is not - if you have copied the reference to a variable outside the method, then you can still access it from the rest of your program. So the outside world can happily use the reference the method returned:
MyClass newUser = MyMethod(registrationInfo);
Console.WriteLine(newUser.Name);
The heap holds the instances of all reference types, the stack holds all the variables your methods declare.
Does that make sense?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Hello!^^ Im currently trying to take all parametres from an object(they are all strings) and pass onto a single string.
To do this i create 3 lists, the first is where all my objects are added, the second is one i use to add all the parametres from a single object from the first list. The second list only hold the parametres of 1 object at a time. When it has all the parametres of the single object it passes them on to my third and final list(and then clears itself) which is the list i want printed with my stringbuilder. If the objects in my first list only contain 1 string, it works just fine, but when the objects has several parametre values the stringbuilder result of the third list returns this : "System.Collections.Generic.Listxxx" instead of the string item in the list, why?
Here is some of the code:
private List<aTableRow> allTableRows = new List<aTableRow>();
private List<string> singleTableRowValues = new List<string>();
private List<string> finalList = new List<string>();
public void SetTableContent()
{
StringBuilder builder = new StringBuilder();
foreach (var tableRow in allTableRows)
{
singleTableRowValues.Add(tableRow.Product.ToString());
singleTableRowValues.Add(tableRow.Price.ToString());
singleTableRowValues.Add(tableRow.StartDate.ToString());
singleTableRowValues.Add(tableRow.EndDate.ToString());
singleTableRowValues.Add(tableRow.Where.ToString());
singleTableRowValues.Add(tableRow.Note.ToString());
singleTableRowValues.Add(tableRow.TippedBy.ToString());
builder.Append(singleTableRowValues).Append(" - ");
tableContent = builder.ToString();
finalList.Add(tableContent);
singleTableRowValues.Clear();
tableContent = "";
}
foreach (var preparedItem in finalList)
{
builder.Append(singleTableRowValues).Append(" - ");
allTableContent = builder.ToString();
}
}
|
|
|
|
|
..because singleTableRowValues on the line below is a list of strings;
builder.Append(singleTableRowValues).Append(" - ");
If you "toString" that, you get the description as in your title. If you want the values from the list as a single string, I'd recommend the string.Join method.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
In addition to what Eddy said about why you're getting "System.Collections.Generic.List", you've significantly over-complicated this!
Consider something like:
public void SetTableContent()
{
StringBuilder builder = new StringBuilder();
foreach (var tableRow in allTableRows)
{
builder.Append(tableRow.Product.ToString()).Append(" - ");
builder.Append(tableRow.Price.ToString()).Append(" - ");
builder.Append(tableRow.StartDate.ToString()).Append(" - ");
builder.Append(tableRow.EndDate.ToString()).Append(" - ");
builder.Append(tableRow.Where.ToString()).Append(" - ");
builder.Append(tableRow.Note.ToString()).Append(" - ");
builder.AppendLine(tableRow.TippedBy.ToString());
}
allTableContent = builder.ToString();
}
"Fairy tales do not tell children the dragons exist. Children already know that dragons exist. Fairy tales tell children the dragons can be killed."
- G.K. Chesterton
|
|
|
|
|
I want to convert ms word file .docx into .html with image and equation without any paid .dll file.
|
|
|
|
|
The way your question is stated makes it look like you are asking for permission. I'm going to guess that you are looking for a free alternative?
A docx-file is a compressed archive (a zip-file) that you can unpack and read.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|