|
You can code this way:
ShellApplicationBase<SomeConcretClassType>.GetInstance().DoNothingAndWaitInfite();
or
ShellApplicationBase<SomeConcretClassType> myInstance = ShellApplicationBase<SomeConcretClassType>.GetInstance();
myInstance.DoNothingAndWaitInfite();
Note that GetInstance() has been changed from Property to a public static method. I'm not sure about if you can use Property before any instance is constructed.
-- modified at 12:43 Friday 8th September, 2006
Best,
Jun
|
|
|
|
|
Hi Jun Du,
One have to know the SomeConcretClassType to access the class type to get the Instance property. What happens now if the class instance was made by
new ShellApplicationBase<ConcreteClassA>();
but one access the singleton inside the application as
ShellApplicationBase<ConcreteClassB>.Instance.DoNothingAndWaitInfite();
as far as I could see this is not the same but it would work, right? There must be a way to retrieve this Instance property on this generic class without giving types to access just the class type, am I wrong?
myMsg.BehindDaKeys = "Chris Richner";
|
|
|
|
|
Chris Richner wrote: One have to know the SomeConcretClassType to access the class type to get the Instance property.
Yes, that is what you used generic class for. If you don't or needn't know SomeConcretClassType, why do you use a generic class?
Chris Richner wrote: What happens now if the class instance was made by
new ShellApplicationBase();
No, you can't call Singleton's contructor directly. It's protected. You have to get the instance via static call GetInstance().
Chris Richner wrote: There must be a way to retrieve this Instance property on this generic class without giving types to access just the class type, am I wrong?
Give a try, but I never thought we could call any method of a generic class without defining a "concret" class first.
Best,
Jun
|
|
|
|
|
public class Test<t> { public static int member; }
Test<int>.member = 2;
Test<string>.member = 3;
Console.WriteLine(Test<int>.member); // outputs 2
Every specialisation of Test<t> will have it's own static fields, so you always need a concrete type. If you just want one instance for all Test<t>, you have to create another non-generic class to hold the field and property.
|
|
|
|
|
Hi,
Thanks for your ansswers, don't get confused about the singelton pattern. I know that I didn't presented the whole code here that the singleton pattern would make sense and run.
It isn't that much about the singleton pattern, just about accessing a static field on a generic class. It seems to me that the big feature I really like about generics is going to make me some troubles accessing a single running instance of class within the application code.
Maybe this is just a indicator that the app design isn't that good yet.
Thanks any way
myMsg.BehindDaKeys = "Chris Richner";
|
|
|
|
|
Hello all,
I have created an application that scans web server logs for specific patterns of traffic. The scan works fantastic and considering the amount of logs it needs to scan, works fairly quickly.
The problem: I have created a status section on my Windows form that updates the status of what file is currently being scanned and what line it's on. As long that the window keeps the focus, the status area works great. If I move the focus to another window and return, the GUI doesn't refresh, but my app is still running correctly.
I have tried launching the scanning method into a new thread and that allows the GUI to refresh, but the application's performance is greatly effected.
Any thoughts on how I can refresh the GUI without multithreading the application? I can give more details if needed.
Thanks!!
SirChuy
|
|
|
|
|
You can occassionally myForm.Update() to force a redraw, but that won't keep the UI thread responsive, it will only force a repaint.
If you want to keep your UI truely responsive (accepting input, etc.), you've really got 2 options.
1. Use a a background thread to do the work. This really should not affect performance greatly as you say it does.
2. Listen for Application.Idle event, and do a little of the processing each time you receieve the event.
Either way, your app will slow down somewhat because now it's doing 2 things: responding to input while painting the UI, and is also processing the logs.
Option #1 is good if you need to do lots of background work that cannot necessarily be split up into smaller tasks. It has the benefit of leaving your UI thread completely dedicated to handling UI requests, but has the downside of introducing possible complexity with thread coordination.
Option #2 is good if you can split up your work into small, discreet tasks that can be run individually. It has the benefit of simpler overall software, since you're only dealing with 1 thread still, but it also has the downside of making the UI thread do some work, which can potentially make your UI look sluggish.
|
|
|
|
|
Thanks for the reply!
I tried the myForm.Update() but, as you mentioned, I still don't have a responsive form. Threading the method wasn't terribly slow but it was a noticable drop in performance. Since the log scanning I do will be in large batches, I'll go with the threading route.
Thanks for your thoughts!
|
|
|
|
|
Hi
How can i get only the file name from string who consist full path?
best regards
when i want to read something good just seat and type it
|
|
|
|
|
fullPath.Substring(fullPath.LastIndexOf('\\')+1)
Is the MSDN really so hard to read?
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Greeeg wrote: Is the MSDN really so hard to read?
No it isn't. Have you read it?
System.IO.Path.GetFileName
only two letters away from being an asset
|
|
|
|
|
So what? Both solutions will work.
My point is that it can't be so hard to open up the MSDN (local or online), go to the string or IO members and look if there's a function that fits my needs.
Nichts für ungut
modified 12-Sep-18 21:01pm.
|
|
|
|
|
You're solution will work, so long as the path seperatation character is a backslash. This is not always the case and is not platform-independent. Using the correct method, pointed to by Mark, will work no matter what the platform or seperation character happens to be.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
i am sorry but i really have not time to read it.Thank's for help
when i want to read something good just seat and type it
|
|
|
|
|
papa80 wrote: i am sorry but i really have not time to read it.
That's funny!! Looking it up on MSDN, or hitting F1 in Visual Studio, probably would have taken you 3 minutes to find the answer. How long did it take you to post the question on CP and wait for answer?
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
string file = System.IO.Path.GetFileName(path);
|
|
|
|
|
I have a work flow management application for a publishing company. On projects with many contributers they use this application to manage all the submission. Sometimes a submission gets sent back to the author to be rewritten, in this case the document is to be attached to the email. I can get it attached and everything works ok, but in the email it has the generic icon and I have reports of it being labeled as an unknown file type. Once I save the document the proper icon appears and everything. Is there a way to set mime type so that it will appear properly in the attachment? Here is the code:
existingAssignment.Push(Convert.ToInt32(ddlCon.SelectedValue), "A", base.uid, dueDate);
Assignment currentAssignment = this.thisArticle.GetCurrentAssignment();
Contributor auth = new Contributor(this.thisArticle.AuthorID);
msg = new MailMessage(Session["ProjectEMail"].ToString(), auth.EMail);
msg.Bcc.Add(Session["ProjectEMail"].ToString());
msg.Subject = this.tbSubject.Text;
msg.Body = this.tbComment.Text;
msg.IsBodyHtml = false;
MemoryStream st = new MemoryStream(currentAssignment.FileBlob);
Attachment att = new Attachment(st, currentAssignment.FileName);
msg.Attachments.Add(att);
SmtpClient mail = new SmtpClient();
mail.Host = "localhost";
mail.Send(msg);
|
|
|
|
|
eggsovereasy wrote: I can get it attached and everything works ok, but in the email it has the generic icon and I have reports of it being labeled as an unknown file type.
I'm sorry, I guess I still don't understand. Where does this icon show up, and where is it generated from?
|
|
|
|
|
Well on my computer, in outlook I get it. The IT people messed up my office by installing Office 2000 over Office XP so I assumed it was an issue with my computer, but now I am getting some reports from other users.
The icon should just be placed on a .doc by the shell.
|
|
|
|
|
In C++ there are the following macros that can be put into strings....
__FUNCTION__ = Returns the current function that "__FUNCTION__" is in. Example "int Foo(int&,CString&)"
__FILE__ = Returns the current file that "__FILE__" is in. Example "C:\main.cpp"
__LINE__ = Returns the current line that "__LINE__" is in. Example 935
Is there something similar in C#?
Thanks Chris
|
|
|
|
|
chris175 wrote: Is there something similar in C#?
There isn't. However, you can retrieve some of this information programmatically. For example, you can retrieve any information about the current function using System.Reflection.MethodInfo.GetCurrentMethod() .
As far as the other things, regarding the file and line of code, there's nothing that can be retrieved programmatically, AFAIK, because once compiled, the file and line information is gone. The only way you could get this is by looking through you're application's PDB debugging database.
|
|
|
|
|
Hello!
I'm trying to create a custom-drawn toolstrip progress bar. The code looks like this:
public sealed class CustomProgressBarEx : ToolStripProgressBar
{
protected override void OnPaint(PaintEventArgs e)
{
}
}
The new paint method is called, but anyway the control still looks like a standard progress bar.
Any idea how to implement this? How can I draw the progress bar myself?
Best regards
Dominik
_outp(0x64, 0xAD);
and
__asm mov al, 0xAD __asm out 0x64, al
do the same... but what do they do??
(doesn't work on NT)
|
|
|
|
|
|
Hi All,
How would one loop a list view? and then after i've done what needed to be done with the item in the listview, move to next item...
i've started like this...
for(int a = 0; a < lvName.Items.Count(); a++)
{
}
Am i starting off correctly?
"Many of life's failures are people who did not realize how close they were to success when they gave up." Thomas A. Edison
|
|
|
|
|
That's correct.
Another nice way is to use this:
foreach (ListViewItem item in lvName.Items)
{
}
regards
modified 12-Sep-18 21:01pm.
|
|
|
|