|
Hi Bob,
In your code, each time we need to write, we need to open the file, go to end (append mode) of the file and write, then close.
I think it is a waste if we write frequently -- we need to open only once and close only once if the file is not automatically closed by some parties for no operation in a long time -- this is why I asked this question about optimization of your code.
Any comments?
regards,
George
|
|
|
|
|
George_George wrote: My question is, if I obtain the handle of the StreamWriter too long without any write operations (for example, 2 days or longer), will the handle (or the underlying file) be closed by some parties (e.g. CLR, OS, etc.) -- like timeout of socket?
I don't think so. GC will reclaim the memory only when no references to that object. A better approach would be to open the file when required, write content and close it though.
|
|
|
|
|
Thanks N a v a n e e t h,
Sorry it is my mistake not to describe the whole situation correcly. The abc actually is a static variable, any comments or updates to my original question about whether file will be automatically closed if open too long without any operation?
regards,
George
|
|
|
|
|
George_George wrote: whether file will be automatically closed if open too long without any operation?
I don't think so, but I am not sure though. GC will collect the instance only when there is no one referring the particular object. Since you use a static variable, it's lifetime will be till the application domain unloads. So I guess there won't be any problem.
|
|
|
|
|
Thanks N a v a n e e t h,
Question answered.
regards,
George
|
|
|
|
|
hey im trying to make an app that will log in to facebook ,
im using the following method to establish connection and post my credentials:
<br />
public static void start_post(string strPage, string strBuffer)<br />
{<br />
byte[] buffer = Encoding.ASCII.GetBytes(strBuffer);<br />
<br />
HttpWebRequest WebReq = (HttpWebRequest)WebRequest.Create(strPage);<br />
WebReq.Method = "POST";<br />
<br />
WebReq.ContentType = "application/x-www-form-urlencoded";<br />
WebReq.ContentLength = buffer.Length;<br />
WebReq.Referer = "http://www.facebook.com/index.php?";<br />
<br />
Stream PostData = WebReq.GetRequestStream();<br />
PostData.Write(buffer, 0, buffer.Length);<br />
PostData.Close();<br />
HttpWebResponse WebResp = (HttpWebResponse)WebReq.GetResponse();<br />
Console.WriteLine(WebResp.StatusCode);<br />
Console.WriteLine(WebResp.Server);<br />
<br />
Stream Answer = WebResp.GetResponseStream();<br />
StreamReader _Answer = new StreamReader(Answer);<br />
reply = _Answer.ReadToEnd();<br />
Console.WriteLine(reply);<br />
}<br />
i get the following respond from facebook:
"sorry, we're not cool enough to support your browser. please keep it real with the following browsers: ...."
any idea how to work around this facebook check , as im sending same data as my IE agent i dont know what else will work , asking for your expert help.
thank you.
Net
|
|
|
|
|
udikantz wrote: as im sending same data as my IE agent i dont know what else will work
And just where do you set that? I dont see it anywhere in your code. Try again.
|
|
|
|
|
i set that in a the main class of the project
these are the parameters that i pass to the method , i chenged the email and password to something fake be it looks something like that:
start_post("https://login.facebook.com/login.php", "challenge=e7d654f99268a01kl94007be0e399755&md5pass=1&noerror=1&email=someemail@gmail.com&pass=coolpassword&charset_test=%E2%82%AC%2C%C2%B4%2C%E2%82%AC%2C%C2%B4%2C%E6%B0%B4%2C%D0%94%2C%D0%84");
Net
|
|
|
|
|
I had the same problem and i used the line
WebReq.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.7) Gecko/2009021910 Firefox/3.0.7 (.NET CLR 3.5.30729)";
it makes the server think that its running FireFox
|
|
|
|
|
hi this code is running fine Facebook Login
protected void Page_Load(object sender, EventArgs e)
{
string strBuffer = "email=xxxxxxxxxxx&pass=xxxxxxxxxxxxx;login=Login";
start_post(strBuffer);
}
public void start_post(string strBuffer)
{
byte[] buffer = System.Text.Encoding.ASCII.GetBytes(strBuffer);
HttpWebRequest WebReq = (HttpWebRequest)WebRequest.Create("https://login.facebook.com/login.php?m&next=http%3A%2F%2Fm.facebook.com%2Fhome.php");
WebReq.Method = "POST";
WebReq.ContentType = "application/x-www-form-urlencoded";
WebReq.ContentLength = buffer.Length;
WebReq.Referer = "http://www.facebook.com/index.php?";
Stream PostData = WebReq.GetRequestStream();
PostData.Write(buffer, 0, buffer.Length);
PostData.Close();
using (HttpWebResponse response = (HttpWebResponse)WebReq.GetResponse())
{
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
{
Response.Write(reader.ReadToEnd());
}
}
}
modified on Monday, November 2, 2009 7:32 AM
|
|
|
|
|
Hi,
I have an TCP server client application, with client running on the WM 6.0.
I have using TcpClient class to establish connection to my server and send data. If I am using wifi the code is working fine, but if I am trying to use GPRS its not working. I think I have to start GPRS connection first. Can someone please tell me how to fix this.
here is the client side code
public class Client
{
public void GpsClient(string Ostring)
{
TcpClient socketForServer;
try
{
socketForServer = new TcpClient("energystudy.dyndns.org", 13000);
}
catch
{
Console.WriteLine("Failed to connect to server at {0}:13000", "energystudy.dyndns.org");
return;
}
NetworkStream networkStream = socketForServer.GetStream();
System.IO.StreamReader streamReader = new System.IO.StreamReader(networkStream);
System.IO.StreamWriter streamWriter = new System.IO.StreamWriter(networkStream);
try
{
string outputString;
// read the data from the host and display it
{
outputString = streamReader.ReadLine();
//Console.WriteLine(outputString);
streamWriter.WriteLine(Ostring);
//Console.WriteLine("Client Message");
streamWriter.Flush();
}
}
catch
{
Console.WriteLine("Exception reading from Server");
}
networkStream.Close();
}
}
|
|
|
|
|
I'm trying to understand the different compiler options in C#.
What exactly is JIT? Is JIT implemented by default or is there a different "default" compiler?
I'm not quite clear on the C# compiler options, relationships and differences. Please explain.
|
|
|
|
|
I recommend doing some reading on the MSDN site. JIT stands for just in time. The C# compiler creates machine code for each part of your program, when it gets run for the first time. There's no other options I know of, excepting that you can buy expensive tools that compile to machine code ( and thus do not need the .NET framework ) all in one go.
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 )
|
|
|
|
|
So each language has its own compileer, right? One for C++, one for VB, one for C#? I assume that each of these compilers has its own JIT functionality. Is this correct?
So is JIT simply a feature of a compiler rather than a type of compiler?
I have read that the C++ compiler supports function inlining but the C# compiler does not. Has MS updated the C# compiler to support function inlining or does function inlining still not exist in the C# compiler? If not then why not?
|
|
|
|
|
Member 3919049 wrote: I assume that each of these compilers has its own JIT functionality. Is this correct?
No, C++ is a different kettle of fish, unless you use C++/CLI. The compiler is actually in the framework.
Member 3919049 wrote: I have read that the C++ compiler supports function inlining but the C# compiler does not
Possibly. One thing to be clear on here - C++ function inlining does not mean you control it. The compiler can choose to inline something without you asking for that, and it can ignore your request. This is part of the c++ standard.
Member 3919049 wrote: Has MS updated the C# compiler to support function inlining or does function inlining still not exist in the C# compiler?
What you need to understand is, the C# compiler works totally differently to the C++ one. There is no inlining in C#.
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 Christian - You really know .NET quite well.
Is there any reason why the C# compiler does not do function inlining?
It seems like function inlining would provide a big performance improvement and it seems like MS has already done the work to define this logic for the C++ compiler so it doesn't seem like it would be too complicated to implement similar logic in the C# compiler....
|
|
|
|
|
Member 3919049 wrote: Is there any reason why the C# compiler does not do function inlining?
I guess they didn't bother to add it.
Member 3919049 wrote: It seems like function inlining would provide a big performance improvement
In very rare cases, perhaps.
Member 3919049 wrote: it seems like MS has already done the work to define this logic for the C++ compiler
The logic is trivial, actually.
Member 3919049 wrote: so it doesn't seem like it would be too complicated to implement similar logic in the C# compiler....
It would be trivial for them to give optional parameters in C#, but have they ? I don't know why.
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 )
|
|
|
|
|
Christian Graus wrote: I guess they didn't bother to add it.
The C# compiler won't do that kind of thing to preserve reflection capabilities, I believe. Inlining happens at the JIT level[^].
For more info, see Eric Gunnerson's Why Doesn't C# have an inline keyword?[^]
Life, family, faith: Give me a visit.
From my latest post: "How differently the psalmist saw it! How blessed -- how truly happy with real joy! -- is the man who delights in the Law of the Lord."
Judah Himango
|
|
|
|
|
Hi All,
I have a datatable with some data :
ActivityNr ActivityStartTime ActivityDuration
001 20:30 00:30
002 20:30 00:40
003 20:30 00:20
As you can see, activity 002 has a longer Duration(40 minutes) then Activity 001(30 minutes) and activity 003(20 minutes).
How can i delete the activities with shorter 'ActivityDuraton' from the datatable and keep the one with the longest 'ActivityDuration???
Assuming the datatable above, the end resulat most be:
ActivityNr ActivityStartTime ActivityDuration
002 20:30 00:40
Thanx.
|
|
|
|
|
Didn't you ask this the other day ? I think you need to ask in the SQL forum, b/c you're asking how to write a query to get these values, right ?
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 )
|
|
|
|
|
hi friends,
i have a program which is for locking the screen (disappers the start menu and other windows) and the form of program appears and wants a password to login and then allows the user to continue his work.
in that program, the programmer has used user32.dll and kernel32.dll by DllImport class.
but the problem is that it works if you are a member of administrators. when i change my group to power users and run the program, an error appears ("an error occured, tell this to microsoft") and the program exits.
i have changed the security accesses of power users from the 'security' tab of windows xp (i have changed access of user32.dll and kernel32.dll in %windir%\system32\ to 'full control') but nothing changed and error again appeared when i run the program in a power user account.
what should i do if i want to use such programs (which uses DllImport) in non-administrator account?
thanks
modified on Tuesday, June 10, 2008 4:55 PM
|
|
|
|
|
You don't need to be an admin to use dll import. You probably need to be one to use the APIs you are calling.
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 for your consideration,
you mean the problem can not be solved in any way?
what should i do to solve this problem?
is the problem for that *.Dll s?
how can i solve my problem then?
thanks again
|
|
|
|
|
Sajjad Izadi wrote: is the problem for that *.Dll s?
No, the problem is that you've chosen to call APIs that only work for an admin. You need to find a different way to do what you're trying to do, read the docs on the APIs you're calling and see which ones require admin, then find a differernt way.
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 )
|
|
|
|
|