|
You can use T as a return type of the Get() method
Giorgi Dalakishvili
#region signature
my articles
#endregion
|
|
|
|
|
|
Thanks man
Giorgi Dalakishvili
#region signature
my articles
#endregion
|
|
|
|
|
I have moved on to another class inheriting this class, and have found a new problem.
here is my code:
public abstract List<T> GetList<T>() where T : Class1,new();
here is my issue. now i am trying to use the same abstract class to make another class, so this one would need to look like:
public abstract List<T> GetList<T>() where T : Class2,new();
however, i cant have them both in the same abstract class, and i cant seem to figure out how to do essentially this (i know this here doesnt work):
public abstract List&lt;T&gt; GetList&lt;T&gt;() where T : (CLass1,Class2),new();
Any ideas?
______________________
Mr Griffin, eleventy billion is not a number...
|
|
|
|
|
As you know C# does not support multiple inheritance of implementation so at most one base class can be used in a constraint.
Just read the documentation: An Introduction to C# Generics[^]
Giorgi Dalakishvili
#region signature
my articles
#endregion
|
|
|
|
|
Hmmm.... I will need to figure out another way. maybe i should not be bothering to include it in the bastract class, for now. this is my project and i am the architect and sole programmer,so it should not be thta big a deal.
Thank you again for all of your help.
______________________
Mr Griffin, eleventy billion is not a number...
|
|
|
|
|
If you want your T parameter to inherit from Class1 and Class2 it means that either Class1 must inherit from Class2 or Class2 from Class1. In either cases you will need to specify just one class as a base class in constraint list as it will automatically mean that T inherits from the second class too.
Giorgi Dalakishvili
#region signature
my articles
#endregion
|
|
|
|
|
Hi all,
Let's say I have a.exe and b.exe. Both are coded in C#.
a.exe have a textbox and a command button while b.exe have a label.
I run both exes. What I want to do is to type something in a.exe, "Hello Wolrd" perhaps, press the command button and have b.exe display the message on the label.
I don't want to use file streams and SQL for this.
Thanks!
|
|
|
|
|
Look up named pipes. I used them a while back for comunicating between a c++ app, and a c# app. It worked out pretty well.
There might be something a little simpler for just C# -> C# but i don't know about it.
My current favourite word is: Nipple!
-SK Genius
|
|
|
|
|
WCF is the way to do this nowadays. The old way I would use for simple stuff is the WM_COPYDATA message.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Thanks!
|
|
|
|
|
I have a Setup Project in which some files are written in Cyrillic fonts (Bulgarian Phonetic). Visual Studio underlines these files and displays a warning Invalid language characters in property 'Name' . When install the files, the Cyrillic fonts appear as junk text - boxes. How can i fix this???
Still learning...
|
|
|
|
|
Hi. I'm making a MDI Windows Form Application that has some child forms.
It behaves like "MS power point slide show". So it shows its child forms in sequence. The child forms have several label controls - about 10 controls each.
My problem is that when each child form shows up, the child form's background image and the label controls are NOT come up concurrently. I've already checked to use double buffering on the child forms but the transition of the child forms is not clear and smooth.
Is there any solution? Like when the form is to be shown, pending any control's display and when the last control's data has written on memroy, then pops up with all the controls at once.
Please help me out!!
|
|
|
|
|
Hi all,
I am getting problem in uploading file with ASP.NET (C#). I have set almost all property of HttpWebRequest instance. I have too set properties in my Virtual directory.
I am getting error as "Cannot connect to the configuration database". I dont know what is configuration database in these case. My application takes 10 second when it execute the below code:
HttpWebResponse httpResponse =httpWebResponse)httpRequest.GetResponse();
I have used Stream to write uploaded file content. It seems to be working fine. Even I am getting my Stream object by GetRequestStream().
========================================================================
here is my code.
string URI = "http://" + txtServerIP.Text + "/" + "VDir" + "/" + fUpload.FileName;
HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(new Uri(URI));
FileInfo fileInfo = new FileInfo(fUpload.PostedFile.FileName);
httpRequest.Method = WebRequestMethods.Http.Put;
httpRequest.AllowWriteStreamBuffering = true;
httpRequest.Credentials = new NetworkCredential(txtUserName.Text, txtPassword.Text);
httpRequest.ContentLength = fileInfo.Length;
httpRequest.ContentType ="text/html";
FileStream fs = new FileStream(fUpload.PostedFile.FileName,FileMode.Open);
Stream stream = httpRequest.GetRequestStream();
contentLength = fs.Read(buff, 0, buffLen);
while (contentLength != 0)
{
stream.Write(buff, 0, contentLength);
contentLength = fs.Read(buff, 0, buffLen);
}
stream.Close();
fs.Close();
//Here it takes 10 seconds.
HttpWebResponse response = (HttpWebResponse)httpRequest.GetResponse();
Could you pls help me.
Thanks,
Regards
Chintan
HCL Technologies...India
(Carefully) listen->(Deeply)Think->(Clearly)Understand->(Patiently) reply...
|
|
|
|
|
|
Hi there,
I am creating my first multi threading app. And I now I'm stuck on here.
Here's my Code:
<br />
public partial class FrmMain : Form<br />
{<br />
<br />
Thread threadVBNums, threadCNum;<br />
private void StartProcess()<br />
{<br />
this.threadVBNums = new Thread(new ThreadStart(this.AddVbNums));<br />
this.threadVBNums.Start();<br />
<br />
this.threadCNums = new Thread(new ThreadStart(this.AddCNums));<br />
this.threadCNums.Start();<br />
}<br />
private void AddVbNums()<br />
{<br />
for(int i = 0; i < 20, i++)<br />
{<br />
this.vbText.Text += ("Main thread: {0}\n", i);<br />
}<br />
}<br />
<br />
private void AddCNums()<br />
{<br />
for(int i = 0; i < 20, i++)<br />
{<br />
this.cText.Text += ("Main thread: {0}\n", i);<br />
}<br />
}<br />
<br />
}<br />
And this is written in Windows Application. So the other code is same as normal CS app. code.
Now this gives me an error saying
Cross-thread operation not valid: Control '' accessed from a thread other than the thread it was created on.
I know that .NET do not allow me access controls on form. But I don't know how to solve this??!!
Can someone tell me what is happening wrong and how to solve it??
- Stop thinking in terms of limitations and start thinking in terms of possibilities -
|
|
|
|
|
To avoid this problem, I would suggest you use a BackgroundWorker. This component will handle much of the threading for you and allow you a way modify controls on the form. It has a few very helpful methods...RunWorkerAsync() , ReportProgress(), and WorkDone().
You can call the ReportProgress method within your for loop like
<br />
private void StartProcess()<br />
{<br />
this.bgWorker.RunWorkerAsync();<br />
}<br />
<br />
private void bgWorker_DoWork()<br />
{<br />
AddCNums();<br />
}<br />
<br />
private void AddCNums()<br />
{<br />
for(int i = 0; i < 20, i++)<br />
{<br />
this.bgWorker.ReportProgress(0, i)}<br />
}<br />
<br />
}<br />
<br />
private void bgWorker_ReportProgress(object sender, ProgressChangedEventArgs e)<br />
{<br />
if(e.ProgressPercentage == 0)<br />
{<br />
int i = (int)e.UserState;<br />
this.cText.Text += ("Main thread: {0}\n", i);<br />
<br />
}<br />
}<br />
<br />
<br />
It's very clean.
Lester
http://www.lestersconyers.com
|
|
|
|
|
You'll have to add a Method to handle it that looks something like this...
private delegate void TextBoxUpdater(TextBox t, String s);
private void UpdateTextBox(TextBox t, String s){
if(t.InvokeRequired) {
t.Invoke(new TextBoxUpdater(UpdateTextBox), Object[]{t, s}));
} else {
t.Text = s;
}
}
Call this from your thread routine in place of manually setting the control text.
The above code may not work, I didn't compile it, but you get the idea. You have to check "InvokeRequired" on a control that you want to cross thread, and call the updating method on the UI thread using a delegate.
Scott
"Run for your life from any man who tells you that money is evil. That sentence is the leper's bell of an approaching looter." --Ayn Rand
|
|
|
|
|
|
Thank you very much half-life.
But is it really safe to do?? I mean what you suggested did work 100% but I read on Internet that this is used for Debugging, just to avoid error messages!
I think someone should write article about Multi-threading on CP. I searched but didn't find any.
- Stop thinking in terms of limitations and start thinking in terms of possibilities -
modified on Monday, April 7, 2008 2:52 PM
|
|
|
|
|
Nothing is Stupid When u do not know it
The Property is MS Idea so it's probebly doable
The right way goes like this:
<br />
public delegate void RefToFunction(string s);<br />
<br />
<br />
RefToFunction handle = new RefToFunction(UpdateTextBox);<br />
<br />
<br />
string s = "Test";<br />
object[] param = { s };<br />
<br />
<br />
this.Invoke(handle, param);<br />
<br />
<br />
public static void UpdateTextBox(string s)<br />
{<br />
MessageBox.Show(s);<br />
}ode><br />
<br />
i did a lot of research about this so i hope i helped<br />
if u need any clarification just reply :):) <br />
<br />
<div class="ForumSig">Have Fun<br />
Never forget it</div>
|
|
|
|
|
don't set CheckForIllegalCrossThreadCalls false, this is a terrible hack, that WILL
result in malfunction, sooner or later (sooner if you are lucky).
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
Bingo, Thanks Luk this is what i intented
Have Fun
Never forget it
|
|
|
|
|
Hello,
I've built a DLL using an ASCII C compiler (NI-CVI). A certain function is to return a string.
Here is the code in C:
int get_description ( char sDescription[] )<br />
{<br />
strcpy (sDescription, "aaa");<br />
return 0;<br />
}
here is the code in C#:
[DllImport("C:\\funcs.dll")]
public static extern int get_description ( out string sDescription);
the exeption I get:
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
I have also tried substituting the string for char[], byte[] nothing works.
Please help me. Anyone?
yariv
|
|
|
|
|
long_il wrote: Please help me. Anyone?
They hide that information in the documentation[^]
led mike
|
|
|
|