|
you need to write your own queue that raises an event if data pushed or poped in/from queue.
|
|
|
|
|
you are correct by saying that the worker thread should be event-driven and should not poll...
I have used the following example to learn from:
Bounded Blocking Queue (One Lock)[^]
and within your worker thread (it must be a thread that is started in the constructor) use:
while (true)
{
lock (syncRoot)
{
while (iCount <= 0)
Monitor.Wait(syncRoot);
class_Message MessageWorker = messageQueue.Dequeue();
iCount--;
.
.
.
this has worked out really well and eventhough it's a blocking queue it works nice and fast !
|
|
|
|
|
I have come across something and wondered if it can be done.
private void Shape_CheckedChanged(object sender, EventArgs e)
{
if (rbDraw.Checked)
{
if (rbSelectShape.Checked)
{
imageViewer1.ShapeSelected = ImageViewer.Shape.Select;
}
if (rbDrawRect.Checked)
{
imageViewer1.ShapeSelected = ImageViewer.Shape.Rectangle;
}
if (rbDrawCircle.Checked)
{
imageViewer1.ShapeSelected = ImageViewer.Shape.Circle;
}
if (rbDrawTriangle.Checked)
{
imageViewer1.ShapeSelected = ImageViewer.Shape.Triangle;
}
if (rbLine.Checked)
{
imageViewer1.ShapeSelected = ImageViewer.Shape.Line;
}
if (rbText.Checked)
{
imageViewer1.ShapeSelected = ImageViewer.Shape.Text;
}
}
Console.WriteLine(imageViewer1.ShapeSelected.ToString());
}
Above is the code i used to check each radio button however i tried tidying it up with the bellow code and couldn't think of a way to set the enum depending on checked radio button.
foreach (RadioButton rb in gbShape)
{
if (rb.Checked == true)
{
imageViewer1.ShapeSelected = ImageViewer.Shape.Circle;
}
}
Any ideas
Thanx in advance
|
|
|
|
|
You can make use of Tag property of the radio buttons for this. While creating the buttons, set the Tag as enum value, like:
rbSelectShape.Tag = ImageViewer.Shape.Select;
Then in your foreach loop, use this:
imageViewer1.ShapeSelected = rb.Tag;
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
|
|
|
|
|
Thank you for the response, that is a great idea and will make things shorter and easier to follow.
Can also do this for the other group boxes on the form.
Thanx George
|
|
|
|
|
In that case i would make a new class called ShapeRadioButton derived from RadioButton.
in that new derived class i would implement a Property called Shape..? from type of your enum.
using the tag would be a solution but i think my solution is not very difficult and would be better programming, think of it you want to use a second object than the tag object is used by you enum and the second gets what ?!? ^^ in the ShapeRadioButton you only need to implement the new property for the type and thats it.
greetz
|
|
|
|
|
I don't think i fully understand how that would work.
class ShapeRadioButton : System.Windows.Forms.RadioButton
{
private ImageViewer.Shape m_shape = ImageViewer.Shape.Select;
public ImageViewer.Shape Shape
{
get
{
return m_shape;
}
set
{
m_shape = value;
}
}
}
i made the class ^ however it still needs to be set somewhere> do you mean the designer will set each RadioButton to have an instance of "ShapeRadioButton". Then use it in the same way as the tag
Thax George
|
|
|
|
|
I have tried this solution however the following error occurs which i do not understand
Error 1 foreach statement cannot operate on variables of type
'System.Windows.Forms.GroupBox' because 'System.Windows.Forms.GroupBox'
does not contain a public definition for 'GetEnumerator'
The code is as follows:
if (rbDraw.Checked == true)
{
foreach (RadioButton rb in gbShape)
{
if (rb.Checked == true)
{
imageViewer1.ShapeSelected = (FileScroller.ImageViewer.Shape)rb.Tag;
}
}
}
|
|
|
|
|
ok use
if (rbDraw.Checked == true)
{
foreach (Control ctrl in in gbShape.Controls)
{
if (ctrl is RadioButton)
{
if (rb.Checked == true)
{
imageViewer1.ShapeSelected = (FileScroller.ImageViewer.Shape)rb.Tag;
}
}
}
}
your RadioButtonClass:
public class ShapeRadioButton : System.Windows.Form.RadioButton
{
private FileScroller.ImageViewer.Shape _shape;
public FileScroller.ImageViewer.Shape Shape{
get{return _shape;}
set{_shape = value;}
}
|
|
|
|
|
That should work only problem being the rb doesnt exsit anymore and ctrl will not allow:
if (ctrl.Checked == true)
|
|
|
|
|
ups sorry i forgot to cast the ctrl into a RadioButton
at rb.Checked use:
if (ctrl is RadioButton)
{
RadioButton rb = ctrl as RadioButton
if(rb.Checked)
{
...
}
}
|
|
|
|
|
Thank you for your help.
This code now works perfectly, i can use it on the other group boxes on the form too.
if (rbDraw.Checked == true)
{
foreach (Control ctrl in gbShape.Controls)
{
if (ctrl is RadioButton)
{
RadioButton rb = ctrl as RadioButton;
if (rb.Checked == true)
{
imageViewer1.ShapeSelected = (FileScroller.ImageViewer.Shape)rb.Tag;
}
}
}
}
Thank you again
George
|
|
|
|
|
I have a windows app in which I want to open a text file in Notepad. When a button is clicked, a file dialog must open which lets the user select a file to be opened in notepad. I know how to create an OpenFileDialog, but I don't know how to open the selected file in Notepad. How does one do this?
|
|
|
|
|
Check out the Process class in the System.Diagnostics namespace.
You should create a Process object, set its StartInfo properties to launch notepad and open your selected text file. Something like this.
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.FileName = @"C:\Windows\notepad.exe";
p.StartInfo.Arguments = @"C:\yourPath\yourTextFile.txt";
p.Start();
|
|
|
|
|
Process.Start(filename) opens the file in its default application, as if you double-clicked it in Windows Explorer.
|
|
|
|
|
Any idea how to do this in ASP.NET?
|
|
|
|
|
hi
I wanna truncate all data in data base
The problem in delete forign key
how i can do that????
|
|
|
|
|
1. Wrong forum.
2. See this[^] link.
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
|
|
|
|
|
|
Hi,
Firstly I am currently a Project Manager so I don't have the detail I would probably have if this was an Open Source issue which I am more familar with. Anyway enough of the caveats.
My understanding is the team create Proxy Classes using WSDL.exe. These classes and then cut and paste into other code which uses them. Please please please don't ask why, accept it does and if you are still reading read on.
What I want to know is,
Does anyone know of any code which could be used to automate this. I was thinking, project managers can, that a pre-compiler of some sort could solve this.
E.g. in the source which need to have the pasted code you could have.
// #AUTO_GENERATED_SOURCE_FILE:Auto_GeProxy_Class.cs #FUNCTION_TO_COPY:My_Foo()
Then make a tool which pre-processing this appropriately.
People are using VS2008
Thanks for listening.
|
|
|
|
|
They need to generate the new proxy class only when there is some change made in the service. Now, since they will be having existing old proxy class, they can use /out or /o switch to directly write the new class to the mentioned location. Like this:
wsdl [service url] /o [file where to write the proxy class]
Is this what you are looking for?
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
|
|
|
|
|
Hi,
Firstly thanks for replying.
I think the original is a code management one. As I said I don't have the detail behind why they are where they are. I think but don't know, that they have some common functions which are split across various projects. They generate the proxy classes and need to ensure all services have these new generated types. I believe they new some of the code a function level to be copied into the other projects.
I have googled for cut and paste from proxies and it does seem that there are few people fallen into this trap in one way or another.
Regards,
Iain
|
|
|
|
|
1. If they are merely adding the new parts of the proxy class to the old one, I would say please don't do it. You might miss out something and it will spoil entire application. Replace the entire proxy class.
2. Say the service had a method Sum which took in "int x" and "int y" as parameters. Later, they changed it to give the sum of three numbers and hence added "int z" as a parameter. Now, they need to change all the calls for the method in the client. Here, there is not much of chance, IMHO, of automation. I am saying so since in your application, the might or might not be as simple as my example. Also, you never know what will be the next change. You also don't know how the clients have consumed the method. If all the consumption ways are different, it will not be an easy task to automate.
If you can clarify what exactly is copied and pasted, maybe someone could give a better response. For now and from my understanding, I don't see much of an automation here.
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
|
|
|
|
|
Iain Wiseman wrote: I think but don't know
We have a saying where I work: "There is no thinking allowed. You either know, or you need to go find out. Thinking only results in misunderstandings and huge bugs."
But, I agree with the other poster. This sounds like a very kludgy way of updating the web service interfaces.
Nothing personal, just my two cents...
|
|
|
|
|
I want to select "FullName","EmployeeNumber" from the datatable 'results' ..The selection should be based on some conditions like date=some date....Can anybody tell how to achieve this???
|
|
|
|