|
|
Sadly, the intelligence of people hoping to make a career in software is plummeting. Just look at the people who ask the most basic questions here because they are too dumb to use google or buy a book. Multiple inheritance is one of the many things C# does not support because the design team were more scared of confusing people than of creating a feature poor language.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Because the designers of the language don't trust us.
Edit: Some language designers would look at existing cars, decide that accelerators cause some people trouble, and design a car without one.
modified on Thursday, November 12, 2009 3:55 PM
|
|
|
|
|
This was a design decision. A properly designed class hierarchy (+ Interface) will allow you to achieve what you can achieve using multiple inheritance.
|
|
|
|
|
Yes... always the same solution "the language don't do it, but you can, doing a lot of code, achieve the same result."
For example, how can you implement "multiple inheritance":
Instead of creating class A and B, which are the base classes of C
(C: A, B) you create IA and IB.
There are the classes A and B, but you only reference them as IA and IB.
So, you create class C: IA, IB
Where all methods of IA call A methods and IB call B methods.
If the methods are non-virtual, you can also create A Extensions and B extensions, that will add methods to IA and IB.
So you will:
Have all virtual methods of A acessible to C using IA interface.
Have all virtual methods of B acessible to C using IB interface.
Have all non-virtual methods that will be acessible in A and B using the A and B extensions methods.
Have all C exclusive methods.
So, typing "c." will list all the methods that will be available using multiple inheritance, but the work to do it will in many cases force you to search for another solution.
|
|
|
|
|
HI,
I am trying to find cpu usage or total processor time of each tab of IE. I am able to just list one main url in the list of application. I am able to list all the url using shdocvw but for that url, I am not able to find totalprocessortime and also for each cpuusage, as i am trying to find the power consumed by each url tab individually,can any body help me on it.
The code i have written is as follows:
using System;
using System.Collections.Generic;
using System.Text;
using System.Management;
using SHDocVw;
using System.Diagnostics;
//using System.ComponentModel;
//using System.Threading;
using System.Net;
using System.IO;
using System.Text.RegularExpressions;
namespace monitor_18_10
{
class Program
{
static void Main(string[] args)
{
// FileStream file1 = new FileStream("d:\\class\\log.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite);
FileStream file1 = new FileStream("d:\\class\\yyyn.txt", FileMode.Create, FileAccess.ReadWrite);
StreamWriter sw1 = new StreamWriter(file1);
FileStream file2 = new FileStream("d:\\class\\log4.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite);
StreamWriter sw2 = new StreamWriter(file1);
Process[] allProcs = Process.GetProcesses();
foreach (Process thisProc in allProcs)
{
//if (!thisProc.HasExited)
//{
// thisProc.Refresh();
string procName = thisProc.ProcessName;
//string totproc = thisProc.TotalProcessorTime.ToString();
int procID = thisProc.Id;
// string totproc=thisProc.TotalProcessorTime.ToString();
//string su=thisProc.StartTime.ToShortTimeString ();
//string su=thisProc.StartTime.ToString ();
//string su = proctime.ToString();
string s = procID.ToString();
string ss = procName.ToString();
// string sss = totproc.ToString();
// richTextBox1.AppendText(s + "\t" + ss + "\n");
Console .WriteLine (s + "\t" + ss + "\n");
sw1.WriteLine(s + "\t" + ss + "\n");
//}
}
sw1.WriteLine("-------------------------------------------------");
Console.WriteLine("-------------------------------------------------");
foreach (Process p in Process.GetProcesses("."))
{
try
//{do
{
// if(!p.HasExited )
// {
// p.Refresh ();
if (p.MainWindowTitle.Length > 0)
{
Console.Write("");
string s2;
string s3;
string pt;
s2 = p.MainWindowTitle.ToString();
s3 = p.StartTime.ToString();
pt = p.TotalProcessorTime.ToString();
//richTextBox2.AppendText(s2 + "\t" + s3 + "\t" + pt + "\n\n\n");
//richTextBox4.AppendText(s3 + "\n\n\n");
Console .WriteLine (s2 + "\t" + s3 + "\t" + pt + "\n");
Console.WriteLine(s3 + "\n\n\n");
sw1.WriteLine(s2 + "\t\t\t" + s3 + "\t\t\t" + pt + "\n\n\n");
//sw1.WriteLine(s3 + "\n\n\n");
//}
}
//} while (!p.WaitForExit(1000));
}
catch { }
}
Console.WriteLine("-------------------------------------------------");
sw1.WriteLine("-------------------------------------------------");
/// cpu usage of each processes
foreach (Process proc in Process.GetProcesses())
{
using (PerformanceCounter pcProcess = new PerformanceCounter("Process", "% Processor Time", proc.ProcessName))
{
pcProcess.NextValue();
//System.Threading.Thread.Sleep(1000);
// Console.WriteLine("Process:{0} CPU% {1}", proc.ProcessName, pcProcess.NextValue());
string cpuname = proc.ProcessName.ToString();
string pcprocess = (pcProcess.NextValue() / 100).ToString();
//richTextBox5.AppendText(cpuname + "\t" + pcprocess + "\n");
Console.WriteLine(cpuname + "\t" + pcprocess + "\n");
sw1.WriteLine(cpuname + "\t" + pcprocess + "\n");
}
}
Console.WriteLine("-------------------------------------------------");
sw1.WriteLine("-------------------------------------------------");
///reading excel data
///
StreamReader SR;
string S;
int i = 0;
SR = File.OpenText(@"d:\\class\\WR111.xls");
S = SR.ReadToEnd();
SR.Close();
Console.WriteLine(S);
string[] words = S.Split(';');
Array.Sort(words);
for (i = 0; i < words.Length; i++)
Console.WriteLine(words[i]);
//this will create the archive
//StreamWriter SW;
//SW = File.CreateText(@"d:\\class\\data2.txt");
for (i = 0; i < words.Length; i++)
sw1.WriteLine(words[i]);
//SW.Close();
//reading excel data ends here
/// cpu usage ends here
// --------------------------------------------------------------------
// List of application processes
// --------------------------------------------------------------------
string processName;
ShellWindows SW = new ShellWindowsClass();
foreach (SHDocVw.WebBrowser IE in SW)
{
processName = System.IO.Path.GetFileNameWithoutExtension(IE.FullName).ToLower();
string s4 = processName;
//Console.WriteLine(processName);
sw1.WriteLine(processName);
if (processName.Equals("iexplore"))
{
string s5 = IE.LocationURL.ToString();
sw1.WriteLine(s5);
Console.WriteLine(IE.LocationURL);
sw1.WriteLine(IE.LocationURL);
String s1 = ReadUrl(IE.LocationURL);
//richTextBox3.AppendText(IE.LocationURL + "\n");
Console.WriteLine(IE.LocationURL + "\n");
sw1.WriteLine(IE.LocationURL + "hello"+"\n");
Console.WriteLine("hi y this stupid is not running");
sw1.WriteLine(IE.LocationURL + "\n");
sw1.WriteLine("hi y this stupid is not running");
sw2.WriteLine(IE.LocationURL + "\n");
//Console.WriteLine(s1);
bool m;
if (m = s1.Contains(".aac"))
//Console.WriteLine("it contains audio");
sw1.WriteLine("it contains audio");
else if (m = s1.Contains(".aif"))
sw1.WriteLine("it contains audio");
else if (m = s1.Contains(".iff"))
sw1.WriteLine("it contains audio");
else if (m = s1.Contains(".m3u"))
sw1.WriteLine("it contains audio");
else if (m = s1.Contains(".mid"))
sw1.WriteLine("it contains audio");
else if (m = s1.Contains(".midi"))
sw1.WriteLine("it contains audio");
else if (m = s1.Contains(".mp3"))
sw1.WriteLine("it contains audio");
else if (m = s1.Contains(".mpa"))
sw1.WriteLine("it contains audio");
else if (m = s1.Contains(".wav"))
sw1.WriteLine("it contains audio");
else if (m = s1.Contains(".wma"))
sw1.WriteLine("it contains audio");
else if (m = s1.Contains(".3g2"))
sw1.WriteLine("it contains video");
else if (m = s1.Contains(".3gp"))
sw1.WriteLine("it contains video");
else if (m = s1.Contains(".asf"))
sw1.WriteLine("it contains video");
else if (m = s1.Contains(".asx"))
sw1.WriteLine("it contains video");
else if (m = s1.Contains(".avi"))
sw1.WriteLine("it contains video");
else if (m = s1.Contains(".flv"))
sw1.WriteLine("it contains video");
else if (m = s1.Contains(".mkv"))
sw1.WriteLine("it contains video");
else if (m = s1.Contains(".mov"))
sw1.WriteLine("it contains video");
else if (m = s1.Contains(".mp4"))
sw1.WriteLine("it contains video");
else if (m = s1.Contains(".mpg"))
sw1.WriteLine("it contains video");
else if (m = s1.Contains(".qt"))
sw1.WriteLine("it contains video");
else if (m = s1.Contains(".rm"))
sw1.WriteLine("it contains video");
else if (m = s1.Contains(".swf"))
sw1.WriteLine("it contains video");
else if (m = s1.Contains(".vob"))
sw1.WriteLine("it contains video");
else if (m = s1.Contains(".wmv"))
sw1.WriteLine("it contains video");
else
sw1.WriteLine("no audio or video in the file");
string type = ExtractApplicationType(s1);
if (type.CompareTo("vedio") == 0)
{
sw1.WriteLine("Running Vedio application");
}
else
{
sw1.WriteLine("Running text application");
}
}
//this.Refresh();
}
//reading data from the meter
//readexceldata();
sw1.Close();
}
static string ReadUrl(string url)
{
//FileStream file2 = new FileStream("d:\\class\\log2.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite);
//StreamWriter sw2 = new StreamWriter(file2);
Uri uri = new Uri(url);
//sw2.WriteLine("hi");
//sw2.WriteLine(url);
//Create the request object
WebRequest req = WebRequest.Create(uri);
WebResponse resp = req.GetResponse();
Stream stream = resp.GetResponseStream();
StreamReader sr = new StreamReader(stream);
string sss = sr.ReadToEnd();
//string sss = uri.ToString();
return (sss);
}
//public static void readexceldata()
// {
// StreamReader SR;
// string S;
// int i = 0;
// SR = File.OpenText(@"d:\\class\\WR111.xls");
// S = SR.ReadToEnd();
// SR.Close();
// Console.WriteLine(S);
// string[] words = S.Split(';');
// Array.Sort(words);
// for (i = 0; i < words.Length; i++)
// Console.WriteLine(words[i]);
// //this will create the archive
// StreamWriter SW;
// SW = File.AppendText(@"d:\\class\\yyy.txt");
// for (i = 0; i < words.Length; i++)
// SW.WriteLine(words[i]);
// SW.Close();
// }
static string ExtractApplicationType(string s)
{
// Line like: "Last</TD><TD ALIGN=RIGHT NOWRAP><B> 78 3/16"
// Line Like embed src
string sPattern = "application/x-shockwave-flash";
if (System.Text.RegularExpressions.Regex.IsMatch(s, sPattern, System.Text.RegularExpressions.RegexOptions.IgnoreCase))
{
// richTextBox3.AppendText(" (match for '{0}' found)", sPattern);
return "vedio";
}
else
{
return "text";
}
// return "text";
}
}
}
Hope to get reply,
thanks in advance...
Cheers..
Namrata
Namrata
|
|
|
|
|
That is a lot of code to look at!
I may be wrong but I believe IE runs everything in one process. The tabs will therefore not show up as separate monitorable processes. That was the whole point of Google Chrome, which is supposedly unique in running each tab in a separate process.
If you have knowledge, let others light their candles at it.
Margaret Fuller (1810 - 1850)
www.JacksonSoft.co.uk
|
|
|
|
|
Google chrome is the only browser that runs each tab in its own process (atleast AFAIK). IE runs all tabs in a single process. Therefore, unless IE provides an interface for you to do it, this is not possible.
|
|
|
|
|
Hello everybody in this forum
when i encode non ascii characters in post method in http using HTTPUtility.URLEncode in C# it gives me an output of encoded string but when i encode the same word in php using urlencode function it gives me a different output
in php it is almost the half encoded string from the one from C# output.
the word that is encoded is : السلام عليكم
in C#
======
%d8%a7%d9%84%d8%b3%d9%84%d8%a7%d9%85+%d8%b9%d9%84%d9%8a%d9%83%d9%85
in php :
========
%C7%E1%D3%E1%C7%E3%20%DA%E1%ED%DF%E3
Almost the half string in php output
i need to output in C# the same encoded string as the output from php
i don't know how to make it
Human knowledge belongs to the world.
|
|
|
|
|
Actually if there is some unicode, the querystring sometimes bigger than what needed. I dont know what is happening inside urlencode of PHP. Perhaps it should be doing the same thing, but using some other Charset.
|
|
|
|
|
.NET String datatype is Unicode. I do not have much knowledge about php, perhaps it is not Unicode. That explains why it is half the size of its C# counterpart.
|
|
|
|
|
Your C# string has 12 bytes, a plus, and 10 bytes.
Your PHP string has 6 bytes, a space, and 5 bytes.
Hence in PHP you're using a special character set, capable of representing all required chars as a single byte; whereas in C# you're using two bytes per char.
Suggestion: find out what the character set ("codepage") is you need, then use new Encoding(codepage) and its GetBytes() method.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
I need to write a .NET application that captures screenshots of various web pages periodically. The application needs to run as a windows service in unattended mode - when there is no user session or when the workstation is locked. A situation similar to: (http://stackoverflow.com/questions/1445788/c-screenshot-of-process-under-windows-service), only, I need to do this on web pages rather than processes.
When I try to use PrintWindow API, I am able to capture inactive or hidden windows, but get a black image when the workstation is locked. Tried this approach (www.devnewsgroups.net/group/microsoft.public.dotnet.framework.windowsforms/topic34231.aspx) but doesn't work.
I know this is possible since there are apps like WebShot (www.websitescreenshots.com) that are able to do it - capture screenshots of web pages even when the workstation is locked or when it runs as a service.
What am I missing? How do I get this to work?
More on my approach - I'm using the .NET WebBrowser control created programmatically. I load the webpage in the browser control and capture the image from it using the PrintWindow API. This I'm able to do whether the control is visible or not, but it trips me up when the workstation is locked.
Thanks much for your time.
|
|
|
|
|
It would be easier if you do it using printscreen.
You can anytime use Graphics.CopyFromScreen(..) to get screenshot programmatically and store it using Bitmap class.
You can easily open program for a second and take the screenshot .
But The main concern is how to do this without actually loading the page, or to do this without showing it in the desktop.
No Idea on this. Hopefully someone else might answer on this.
But for the time being, this might be your solution. If not, please let me know.
|
|
|
|
|
I can only think of one solution, and it is a lot of work. You parse the URL, instead painting to screen, you just save it to image file. I doubt it is possible to make screen shot of a window, while system is locked
|
|
|
|
|
Yes Saksida...
You are right. Just for curiosity, I did this and found the program errors out if I try to take screen shot of a window while system is locked.
It produces System.ComponentModel.Win32Exception - "The handle is invalid" on g.CopyFromScreen call.
|
|
|
|
|
Hi,
Please let me know where can i find the diff b/w c# and c++
|
|
|
|
|
|
Have you even attempted to look for any information on your own?
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
I guess posting on codeproject is easier than searching Google.
If you have knowledge, let others light their candles at it.
Margaret Fuller (1810 - 1850)
www.JacksonSoft.co.uk
|
|
|
|
|
There's plenty of answers to that question online.
|
|
|
|
|
hi , sorry my english is very bad so, can you help me if a write my problem in french
..
"pour simplifier ma question,
je débute en programme c# et le Pb est le suivant :
dans mon application je possède deux formulaires form1 et form2 et supposons que dans le code source de form1 j'ai 'X' une variable qui a pour valeur '6',et aussi dans form1 j'ai un boutton qui me permet de basculer a form2 et dans le code source de cette dernière je voudrai utiliser (ou récupérer)cette valeur c-à-d "6" pour d'autres calcules . voila j'espère avoir été assez claire"
Friends any help is greatly appreciated
|
|
|
|
|
où est la question?
it is yet again a "how do we pass a variable, an object, a whatever from one Form to another?". this gets asked and answered on a daily basis, although it is fundamental and covered in every introductory book.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
I'm afraid my french is non-existent, though I managed to work out your question without difficulty. No chance of replying in French though I am afraid.
in the button click on form1 you can pass the value of x to form2, either as a parameter in the constructor, or by creating a property on Form2 that you set in the button click event.
Pretty basic .Net coding really. When is the homework due in?
If you have knowledge, let others light their candles at it.
Margaret Fuller (1810 - 1850)
www.JacksonSoft.co.uk
|
|
|
|
|
Have you tried "Google Translate"?
I don't understand French
Avez-vous essayé "Google Translate"?
Je ne comprends pas le français
public class Form2 : Form
{
<snip>
public String someText = "OO";
<snip>
}
public class Form1 : Form
{
<snip>
public void ButtionOk_Click(Object, System.EventArgs e)
{
Form2 frm = new Form2()
frm.someText = "NOPE";
frn.show();
}
<snip>
}
|
|
|
|