|
I am not sure if there's a question in here. I am guessing you are saying 'the code I am not showing you is not doing what I want. I am not being clear about what I want, but please fix it'. Sorry, my crystal ball is broken.
Also, a picture box is almost certainly the wrong way to do this, a picture box is only there for people too dumb to write 3 lines of imaging code, but what a picture on their form.
Christian Graus
No longer a Microsoft MVP, but still happy to answer your questions.
|
|
|
|
|
Is there a way to access the explicit interface implementation of a base class from a dervied class without using reflection ?
Because the following lines wont compile, and i dont understand why i shouldn't.
public interface ISomeInterface {
void SomeMethode();
}
public class BaseClass : ISomeInterface {
object SomeInterface.SomeMethode{
...
}
}
public class DerivedClass : BaseClass, ISomeInterface {
object SomeInterface.SomeMethode{
( ( ISomeInterface ) base ).SomeMethode();
}
}
|
|
|
|
|
Why do you declare public class DerivedClass : BaseClass, ISomeInterface at all? Shouldn't public class DerivedClass : BaseClass be enough to ensure that DerivedClass implements ISomeInterface?
|
|
|
|
|
Because i couldn't implement the interface explicit
|
|
|
|
|
MarkPhB wrote: Because i couldn't implement the interface explicit
You need to explain what you mean by this. Implementing an interface explicitly is done for a reason, you might not have wanted to implement the interface explicitly in the first place!
|
|
|
|
|
As ive said above its not entirely clear what you are trying to achieve. However, you can access that explicit interface in the derived class without also implementing the interface.
public interface ISomeInterface{
void SomeMethod();
}
public class BaseClass : ISomeInterface {
void SomeInterface.SomeMethode(){
...
}
}
public class DerivedClass : BaseClass{
void AnotherMethod(){
((ISomeInterface)this).SomeMethod();
}
}
Incidentally if you change BaseClass too the following the commented out line above will work. This is implementing the interface implicitly
public class BaseClass : ISomeInterface {
public void SomeMethode(){
...
}
}
|
|
|
|
|
J4amieC has given you the correct answer above.
It's the difference between explicit and implicit.
If you want to change a value from one type to another in code then if an implicit operator exists you can just set one to equal the other. If not, you have to explicitly cast to the type you require.
The same applies to interfaces. If you implement them explicitly then the cast is required in any classes that derive from the class where the implementation was made.
((ISomeInterface)this).SomeMethode();
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Expect everything to be hard and then enjoy the things that come easy. (code-frog)
|
|
|
|
|
hi
i have two thread that run two different methods.
in both methods i write a code that read a data from database.
for reading data from database i use sqlDataReader object.
assume two below area code:
first method(for first thread):
cmd.commandText="sql query";
sqldatareader dr=cmd.executereader();
if(dr.Hasrows)
{
dr.Read();
// in here i have a problem when another threads try to execute dr.Read() command of another methods
// because still this datareader object is not close. and the exception error is :
//"invalid try to read data. a datareader must be closed first."
}
dr.Close();
.........
second method(for second thread):
cmd.commandText="second sql query";
sqldatareader dr=cmd.executereader();
if(dr.Hasrows)
{
dr.Read();
// in here i have a problem when another threads try to execute dr.Read() command of another methods
// because still this datareader object is not close. and the exception error is :
//"invalid try to read data. a datareader must be closed first."
}
dr.Close();
-------------
please attention this two methods have completetly different code but in both of them should be read a data from database with sqldatareader. i need a class such as Monitor.Enter(Object) to lock this area codes but the problem is this two area codes are not in one method.
please tell me a solution.
thanks alot.
nobody help you...
you have to help you yourself
and this is success way.
|
|
|
|
|
Why don't you let each thread open its own connection?
|
|
|
|
|
thank you frank but i think you didnt understand my problem.
when i open a connection to a database with sqldatareader, i can not open another connection to that database or anyoneelse untill previouse connection will be close.
but in multi threading its maybe happen. what should i to do to avoid to this critical error????
nobody help you...
you have to help you yourself
and this is success way.
|
|
|
|
|
mr.mohsen wrote: i can not open another connection to that database or anyoneelse untill previouse connection will be close.
In that case you don't need multiple threads.
If you use multiple threads you need to synchronise access to the
connection so only one thread can use it at a time...may as well
just use one thread.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I think Frank has the correct solution. Your code does not show where you create the SQLCommand object and assign it a connection. Each connection can have only 1 datareader open. If you instantiate a command and connection IN each thread it will work.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
hello 4 all
How can i get all of the forms in the project For exable:
foreach (Control cont in this.Controls)
MessageBox.Show(cont.Name + " " + cont.Text);
but instead of getting the controls i want to get all of the form in certin project
thx
|
|
|
|
|
Hi,
If this is a MDI application, iterate through main window's MdiChildren property
Mika
|
|
|
|
|
Hello
I am basically a Micro controller programmer trying to learn C# for controlling my devices through serial port.(USB is next target).
I have seen serialport control and its events in C#2008. Also I went through some example projects in Code project. They seem to be not using that control. They are using coding only using Serialport class of dot net.
Let me express some of my basic doubts. (My doubts arise out of my comparatively low speed and sequential programming experience in Micro controllers- so it seems to me)
Suppose I need to do a task when I received 20 bytes from serial port. I understood that data received is in a buffer. But I need to act only when a particular number of bytes is received. Or a particular character or null is received.I have seen the time out property, but in my case data may come at different quantity. So time out may not be practical. How I can realize this requirement?
In another situation sometimes a packet of 30 bytes arrives in a strech - means sequentially and stops. Means that packet ends and there will be a pause of substantial time before next packet comes. Here I need to get informed that one packet received and stopped, so my task will jump in. In micro controllers I use interrupts and all. Here it seems to me that more easy and flexible options are available. but I don't get the clue.
Any guidelines for where I to look or follow which method?
With Regards
Roy Thomas
"..this file is known as source file probably because it is a source of frustration and anxiety!" - Chuck Sphar - In book 'C# 2005 for Dummies'.
modified on Saturday, August 9, 2008 10:57 AM
|
|
|
|
|
Have you tried using the DataReceived event from the System.IO.Ports.SerialPort?
|
|
|
|
|
Thanks for the reply.
I am trying that now. But It will create an event when each data received- means for each byte. But I need to act only when 20 bytes are received.
So read the buffer on each event, append it to a user array, and check for the end of packet-- is this the suitable and possible method?
With Regards
Roy Thomas
"..this file is known as source file probably because it is a source of frustration and anxiety!" - Chuck Sphar - In book 'C# 2005 for Dummies'.
|
|
|
|
|
MSDN says
"The DataReceived event is not guaranteed to be raised for every byte received. Use the BytesToRead property to determine how much data is left to be read in the buffer."
What does this mean? If the event is not guaranteed how can we get the complete and correct string coming through serial port?
With Regards
Roy Thomas
"..this file is known as source file probably because it is a source of frustration and anxiety!" - Chuck Sphar - In book 'C# 2005 for Dummies'.
|
|
|
|
|
I think I have found some clue.
To get a particular number of bytes we can set the receive threshold as ..say 20. Then receive event will be triggered when serial port receives 20bytes.
Unlike in Micro controllers windows cannot give events (Interrupts ) guaranteed for every byte received. I have tried by making a device connected to serial port which sends some lengthy strings. If I send bytes with a few 10s of milliseconds gap from the embedded device, I am getting an event for every byte. But if I send a continuous data stream with no delay in between, events are triggered at no uniform intervals. sometimes 8 bytes sometimes 40 bytes. even if receive threshold is set to 1 byte.
So what I found as the best method is make receive threshold as 1 byte, on receive event use BytesToRead method to get all bytes received so far and append it to a string. also on every event clear a timer count to 0. When the packet ends the timer count will not gets cleared in time so that it will climb up and creates a user event.(working on that)on the event can check for a EOF to confirm a valid packet.
Why this complex machine cannot give a timely event while a small Microcontroller can do it in correct time?
With Regards
Roy Thomas
"..this file is known as source file probably because it is a source of frustration and anxiety!" - Chuck Sphar - In book 'C# 2005 for Dummies'.
|
|
|
|
|
|
How can i count the number of characters used out of provided in a text box.I mean when a user enters some text in a text box provided how can i show he has used x out of y characters with each keystroke in real time?Can anyone provide code in C#?Thanks
|
|
|
|
|
Set the MaxLength property of your textbox to some value (like 200), then in the TextChanged event of the textbox you can write some information into a label if you like:
private void textBox1_TextChanged(object sender, EventArgs e)
{
label1.Text = string.Format("You use {0} out of {1} characters", textBox1.Text.Length, textBox1.MaxLength);
}
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Please tell me the link for learning the mobile programming
|
|
|
|
|
try to search in google
there are a lot of good results on a few first pages...
nobody help you...
you have to help you yourself
and this is success way.
|
|
|
|
|
Hi,
I want to trigger an event every time I type something in a textbox using Onchange events.
The code im using is
IHTMLElementCollection elcol1 = doc.getElementsByTagName("input");
foreach (IHTMLInputTextElement iel in elcol1)
{
HTMLInputElementClass ee = iel as HTMLInputElementClass;
if (ee.value!= null && ee.IHTMLInputElement_type.Equals("text"))
{
ee.HTMLInputTextElementEvents2_Event_onChange += new HTMLInputTextElementEvents2_onChangeEventHandler(ee_HTMLInputTextElementEvents2_Event_onchange);
}
}
For every text element it enters into the "if" block but the "ee_HTMLInputTextElementEvents2_Event_onchange" function is not called. How can i trigger the event? Please help!
|
|
|
|