|
I am by no means an expert, so don't take this answer as gospel. I am posting more to see if the gurus out there will correct any bad assumptions I have.
As I believe: C++ is based on C. When C was created there was a need to keep compilers efficient - CPU time = $$$$. Therefore, the C language was designed with the idea that its compilers should not need to make multiple passes of the code. In a single-pass compiling strategy, you have to know what something is before you can use it. Hence procedures and variables had to be declared before they could be used. That led to the need for header files and forward declarations.
I don't know if C++ compilers really need forward declarations, or whether it was just a carry over from C. But either way, this why I believe C++ has header files too.
C# simply broke the tradition. If you allow your compiler to go over the code once and categorize the classes/methods/properties/fields and then go over it again to compile it, then there is no need for forward declaration, nor for header files.
Am I way off base, Gurus?
Clive Pottinger
Victoria, BC
|
|
|
|
|
That's right; Eric Lippert explained it in more detail on his blog[^]
|
|
|
|
|
Ah!! Multiple parsing is the secret!!
Thank you very much Clive for answering my question and thank you Harold for sharing that wonderful link.
|
|
|
|
|
In C++ the compiler only needed a function's prototype or a class declaration, both usually found in headers. The compiler left it to the linker to locate the implementations and resolve those dependencies. When working with C++, this is a common error. The compiler compiles all sources without problems, but the linker stops with an error because you forgot to tell it where to locate a library which belongs to one of the headers you have included.
So you may very well see the linker as a second pass after compiling.
And from the clouds a mighty voice spoke: "Smile and be happy, for it could come worse!"
And I smiled and was happy And it came worse.
|
|
|
|
|
Hello Gurus.
Yes, I've painted myself into yet another corner. It seems to be what I do best, so I guess I should stick with it.
This time I am trying use reflection to find an event that I have attached to a class, but reflection is not showing the event. I don't know why.
I have created a simple class called ListPicker that is based on the DomainUpDown control. It is supposed to act just like a DomainUpDown control, but it supports the Modified property and the ModifiedChanged events that DomainUpDown does not. Here is the code:
using System;
using System.Windows.Forms;
namespace WindowsFormsControlLibrary
{
public partial class ListPicker : DomainUpDown
{
public EventHandler ModifiedChanged;
public ListPicker()
{
InitializeComponent();
TextChanged += new EventHandler(ListPicker_TextChanged);
Modified = false;
}
public bool Modified { get; set; }
public void ListPicker_TextChanged(object sender, EventArgs args)
{
Modified = true;
OnModifiedChanged();
}
protected void OnModifiedChanged()
{
if (ModifiedChanged != null)
{
ModifiedChanged(this, null);
}
}
}
}
The Modified property works just as I wanted it to, and the ModifiedChanged event fires when it is supposed to, but when I use this code (where ctl is a reference to the ListPicker control)
var x = ctl.GetType().GetEvents();
var modifiedChangedEventInfo = ctl.GetType().GetEvent("ModifiedChanged");
to look for the events on the ListPicker, it does not show the ModifiedChanged event. All the other DomainUpDown event show up in x, but not the ModifiedChanged event and modifiedChangedEventInfo is null
Any ideas? ... and many thanks
Clive Pottinger
Victoria, BC
|
|
|
|
|
Of what type is ctl? Is it of the class DomainUpDown or of ListPicker? If it is of DomainUpDown, you probably only see the events of this class and not of any derived classes.
And from the clouds a mighty voice spoke: "Smile and be happy, for it could come worse!"
And I smiled and was happy And it came worse.
|
|
|
|
|
that must be because it isn't an event, it is just a delegate. Add the event keyword to your declaration and it should show up.
|
|
|
|
|
Good eyes! I just saw what I expected to see.
And from the clouds a mighty voice spoke: "Smile and be happy, for it could come worse!"
And I smiled and was happy And it came worse.
|
|
|
|
|
Whoa! I feel like I've just gone to the hospital to ask a surgeon why I keep getting headaches whenever I hit my head with a hammer. There should be a facepalm emoticon.
Thanks guys. I'll apply your suggestion to the code tonight and see what happens.
Clive Pottinger
Victoria, BC
modified 15-Nov-11 12:38pm.
|
|
|
|
|
Yup - that was it.
embarassing... that's all I have to say... embarassing
oh, and thanks.
BTW: I find it interesting that the question from one C.D.P was answered by another C.D.P.
Clive Pottinger
Victoria, BC
|
|
|
|
|
Don't worry.
And you're welcome.
BTW: you shouldn't reply to self, as nobody gets mail notification when you do.
|
|
|
|
|
Clive D. Pottinger wrote: BTW: I find it interesting that the question from one C.D.P was answered by
another C.D.P
In my case the 'CDP' has nothing to do with my name or initials. A CDP1802 or RCA1802[^] was the CPU in my first computer. Look closely at the assembly code sample. One of the instructions, the one to designate the stack pointer, still does not fail to bring a wide grin to programming.
And from the clouds a mighty voice spoke: "Smile and be happy, for it could come worse!"
And I smiled and was happy And it came worse.
|
|
|
|
|
An instruction any man would love to comply with I think
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman
|
|
|
|
|
Yes, who does not like to set the stack pointer
And from the clouds a mighty voice spoke: "Smile and be happy, for it could come worse!"
And I smiled and was happy And it came worse.
|
|
|
|
|
Good catch. I read right over that.
|
|
|
|
|
Hi,
I have an Web Application developed in .NET Framework 4.0 and created an deployment setup for the same. The client requirement is to create an custom Apppool and assign it to the virtual directory which is currently installing. To address this issue i created an custom actions project as described in following article.
http://weblogs.asp.net/scottgu/archive/2007/06/15/tip-trick-creating-packaged-asp-net-setup-programs-with-vs-2005.aspx[^]
I wrote the following code to create an apppool and assign it to the virtual directory.
private void CreateAppPoolIIS7()
{
using (ServerManager serverManager = new ServerManager())
{
string appPoolName = this.Context.Parameters["APPPOOL"];
ApplicationPool newPool;
newPool = serverManager.ApplicationPools.FirstOrDefault(x => x.Name == appPoolName);
if (newPool == null)
newPool = serverManager.ApplicationPools.Add(appPoolName);
newPool.ManagedRuntimeVersion = "v4.0";
newPool.ManagedPipelineMode = ManagedPipelineMode.Classic;
serverManager.CommitChanges();
}
}
private void AssignIIS7AppPoolToVirDir()
{
using (ServerManager serverManager = new ServerManager())
{
Microsoft.Web.Administration.Application newApp = null;
string appPoolName = this.Context.Parameters["APPPOOL"];
Site site = serverManager.Sites.First(s => s.Id == 1);
string installpath = this.Context.Parameters["INSTALLDIR"];
installpath = installpath.TrimEnd('\\');
string virdirname = "/" + installpath.Substring(installpath.LastIndexOf('\\') + 1);
newApp = site.Applications.FirstOrDefault(x => x.Path == virdirname);
if (newApp != null)
{
newApp.ApplicationPoolName = appPoolName;
serverManager.CommitChanges();
}
else
{
MessageBox.Show("Website not found");
}
}
}
I call these methods in the Install event of the installer as follows..
public override void Install(IDictionary stateSaver)
{
.......
CreateAppPoolIIS7();
AssignIIS7AppPoolToVirDir();
The assigned app pool is reflected in the IIS as long as the control is in the custom action project. The apppool resets back to the default selected at the start of the installer once the setup exits the custom action project.
It would be grateful if some one could help.
When you fail to plan, you are planning to fail.
|
|
|
|
|
Hi All,
I am using the WPF ribbon Library in my application for getting a ribbon control attached in my application.
I need the functionality where I can trap the minimize event in ribbon and do some additional stuff of code in there.
But, to my surprise I could not find any property named Minimized in ribbon .. I could found out collapsed and Expanded but they were of no use.
Can some body tell me what does IsMinimize property correspond to. As,if I know for which property the minimize functionality is attached,I can then easily solve my problem statement.
-Kushagra
I believe in Me !!!
|
|
|
|
|
|
I have an XNA application which runs in several threads. One thread takes care of the 3D rendering, the other one is a GUI with the application logic. The controls of the GUI are also drawn by the rendering thread, therefore some thread synchronization between the UI thread and the rendering thread exists. Basically this is neeeded only when a control's properties are changed so that the control must be redrawn. Locks are only needed while those properties are changed, so that a control is not accidentally drawn with only half of the changes, causing ugly rendering glitches. This synchronization is only brief and does not cause any visible delay in rendering or in the performance of the UI thread.
The UI thread makes use of a webservice to fetch or write data from and to the server. With synchronous webservice calls I would expect the UI thread to freeze up while waiting for the response. This should have no bearing on the rendering thread, as the UI thread is waiting and not making any changes to controls. Against this expectation, the rendering thread also briefly freezes when a web method is called.
Using asynchronous webservice calls solves the problem and will be the way to go, but I also would like to understand what is going on. I use a quad I7 proceesor at 4 GHz, so calling a web method in a multithreaded application should (and does not) generate a CPU load of 100%. Also it cannot be because of thread synchronization.
And from the clouds a mighty voice spoke: "Smile and be happy, for it could come worse!"
And I smiled and was happy And it came worse.
modified 15-Nov-11 7:58am.
|
|
|
|
|
How are you determining that the rendering thread freezes? Obviously anything it tries to display will get delayed, and if you have any event handlers which call Invoke onto the UI thread, those will also cause a synchronisation point. The debugger is primarily attached to the UI thread and so if you're looking at it in there it might also show a freeze, which could be an artifact of the debugging environment.
|
|
|
|
|
Thank you. The program at the moment uses a simple animated scene (a continuously rotating model) in the background and the current frame rate is displayed. When web methods are called, the rotation of the model stops for the duration of the call and the frame rate is not updated. Then it resumes and the frame rate briefly is displayed as 0, indicating that the rendering thread indeed stood still during that time. No such delays happen when the webservice calls are commented out.
Edit: Just to be precise: I had started it in debug mode, but there were no breakpoints. It was the mere presence of the debugger which caused this behavior. When I come home I will take a look how well the current version fares.
I have an older version of the project here and just compiled it with 'Release' settings and started the program from Windows Explorer, so that the debugger was not present in any way. It worked as expected: The UI thread waited when calling the webservice, briefly freezing the UI. Meanwhile the animated 3D rendering in the background continued without any visible delay or drop in the frame rate, even when slower web methods were called.
I'm glad that the debugger was the culprit and that there is no hidden bug which may come back and cause even more trouble.
And from the clouds a mighty voice spoke: "Smile and be happy, for it could come worse!"
And I smiled and was happy And it came worse.
modified 15-Nov-11 11:01am.
|
|
|
|
|
Hi
I have the regex below to split words and not split a string ".. .." instead take the whole string as on item to a List.
Example:
text="all "1 dl""
after split
all[0]="all"
all[1]="1 dl"
I found it in Google and it works, but I don't understand how it works.
string regexSpliter = @"(?<=^(?:[^""]*""[^""]*"")*[^""]*) ";
List<string> all =new List<string>_ (System.Text.RegularExpressions.Regex.Split(text, regexSpliter));
And if I remove the space before the last " in the string it doesn't work as I want. It seems like it splits all the characters written in the string text.
Can anybody please explain the string regexSplitter and why it has to be a space last in the string.
Many thanks
Fia
|
|
|
|
|
|
I truly appreciate the "deep art" of RegEx expressions, although I'd never spend time trying to reverse-engineer what any complex one, like this, does. My understanding is they are expanded internally into lots of code, but, when compiled, give excellent performance.
Meanwhile, have you considered an alternative like:
char[] c = new char[] {'\"'};
string s = "all \"1 dl\"";
List<string> sList = (s.Split(c)).Where(str => str != "").ToList<string>(); Disclaimer: the above code was created very quickly, and tested only on your input string, making the assumption that you would have to escape the internal quote delimiters.
On your input it does work to create a two element List<string>, whose elements match the results of your RegEx.
Whether the above code is appropriate/robust, etc., for your parsing needs, I have no idea; it's meant only to show the possibility of an alternative.
good luck, Bill
"I have always wished for my computer to be as easy to use as my telephone; my wish has come true because I can no longer figure out how to use my telephone." Bjarne Stroustrop circa 1990
|
|
|
|
|
It's basically saying 'split on space or on this big group which matches a quoted string'. I guess the fact it's a parenthesised group is how it ends up being returned even though it was the split expression. I don't fully understand it but that's the basic idea.
This isn't how I would parse a command string, I have some code for that in my Lobby Server article:
using System.Text.RegularExpressions;
namespace RedCorona.Util {
public class Command {
public static string[] Parse(string text){
if(text.IndexOf('"') < 0) return text.Split(' ');
else{
MatchCollection mc = Regex.Matches(text, "\"(?<word>[^\"]*)\" *|(?<word>\\w+)");
int len = mc.Count;
string[] res = new string[len];
for(int i = 0; i < len; i++) res[i] = mc[i].Groups["word"].Value;
return res;
}
}
}
}
I'm not sure if MatchCollection implements IEnumerable<string> and therefore whether you could do a one-liner as you have done there; this code comes from pre-generic days (which is why it returns an array not a List<string>). My simple brain can only think in terms of the matched groups not the delimiters so this regex matches a quoted (first part) or unquoted (second part) 'word'.
|
|
|
|