|
Calvin Bell wrote: So what would I do there?
You need to evaluate your design and decide how the code should work, rather than simply tweaking the code to compile and run under circumstances. What DateTime do you want to do if the license is not found? A null reference, DateTime.MinValue , something else? The choice is yours.
/ravi
|
|
|
|
|
my server implements a reading thread that blocks until data is received.
what I'd like to do is have a designated thread that only writes as data becomes available (an event would be created that contains the TcpClient in the event argument).
Therefore the question: is it possible to use TcpClient.GetStream() twice for the same TcpClient ?
|
|
|
|
|
It's not possible.
'tcpclient.getstream() ' can get all btye[] by server socket sending.
April
Comm100 - Leading Live Chat Software Provider
modified 27-May-14 21:53pm.
|
|
|
|
|
Yes, it's possible.
You can't read or write by two threads, but having a thread that only reads and a thread that only writes is perfectly possible. I always do this but, in fact, I call GetStream only once, and pass the returned stream as the parameter to the threads, but I really think this don't change anything.
Also, be carefull not to close the stream before you finished, as closing the stream will also close the tcp/ip connection.
|
|
|
|
|
passing the TcpClient object around and calling GetStream() once in the read thread and once in the write thread worked just fine.
Since I found this out I have updated my code to use a secure socket and now I'm passing around a NegotiateStream object (but no need to call GetStream)
|
|
|
|
|
Hi,
In c# i generated HTML report (colored).
I am using Webbrowser control.
I need to print it. But unfortunately i cannot print the color (background color). why?
A sample report is as below.
<html>
<head>
<title>Test</title>
</head>
<body align=center >
<table align=center border=0 width=1000>
<tr>
<td align=center class=title style='border:2px solid red;'>110P-1 PRODUCTION SCHEDULE</td>
</tr>
</table>
<table align=center border=1 width=1000 cellspacing=0 cellpadding=0>
<tr>
<td colspan=3 align=right> <b>TOTALS:</b> </td>
<td align=center ><b>22160.00</b></td>
<td align=center ><b>15828.57</b></td>
<td align=center ><b>18000.09</b></td>
<td align=center><b>2971.36</b></td>
<td align=center><b>33</b></td>
<td > </td>
</tr>
<tr>
<td align=center ><b>DEL.DATE</b></td>
<td align=center ><b>COLOUR</b></td>
<td align=center><b>ADDRESS</b></td>
<td align=center ><b>L/M</b></td>
<td align=center ><b>HOURS@1.4m</b></td>
<td align=center ><b>COMPLETE</b></td>
<td align=center ><b>REMAIN HOURS</b></td>
<td align=center ><b>PACKS</b></td>
<td align=center ><b>STATUS</b></td>
</td>
<tr><td align=center > 20/11/2009</td>
<td align=center style='background-color:#FF8C00;'> </td>
<td align=center > Hamilton Iland</td>
<td align=center > 20310.00</td>
<td align=center > 14507.14</td>
<td align=center> 18000.09</td>
<td align=center > 1649.94</td>
<td align=center > 33</td>
<td align=center > </td></tr>
<tr><td align=center > 16/11/2009</td>
<td align=center style='background-color:#14A0E6;'> </td>
<td align=center > Bankstown</td>
<td align=center > 1250.00</td>
<td align=center > 892.86</td>
<td align=center > 0.00</td>
<td align=center > 892.86</td>
<td align=center > </td>
<td align=center > </td></tr>
</tr>
</table>
</body>
---------------------------------- ---------------------
I am using .NET framework 3.5
I have color printer. and if i changed table border to red, blue, etc for border, it prints in color.
It only does not work with table cell (TD) background color.
Thanks in advance
Shukra
|
|
|
|
|
Because it follows the settings for Internet Explorer, which, by default, doesn't print the background at all.
|
|
|
|
|
To follow up on Dave's response, you don't need to use a WebBrowserControl to print your document. Simply save the HTML to a temporary file and do the .NET equivalent of ShellExecute (..., "print", ...) to print it. The .NET equivalent is Process.Start() .
/ravi
|
|
|
|
|
Thanks Ravi,
Will you pls tell me if.
Is there any way to change IE printer settings from c# code?
1.I want to dynamically set page orientation to "Landscape" or "Portrait"
2.I want to remove the header or footer. (I can change the values from registry, but don't know how to disable it?)
Thanks again,
Shukra
|
|
|
|
|
|
Hi,
I am currently doing some research to see which of these wrappers of OpenCV to use for myfinal year project. I am looking to develop something in C# to recognise the movement of a hand.
Any advice is appreciated.
Cheers!
|
|
|
|
|
Great! Was there a question in there, or did you just want to announce to the world what you're doing?
|
|
|
|
|
My Bad! Engrossed in this thing I cant think straight!
I want to find out which one is better. Thanks in advance for your suggestions!
|
|
|
|
|
The one that meets all of your specifications.
"Better" is a subjective term. The only way you're going to know is to test each one against what you want to do.
|
|
|
|
|
Hi
Is there a way of writing and reading a csv file from C# at the same time?
I mean I have two separated projects; one keeps writing data into a csv file and the other one is to read the data from the same csv that is also being written.
When I tried this, it always says the file can't be accessed because it's being used by another process.
Is there anyway of getting around this?
Many thanks indeed.
|
|
|
|
|
Tony4966 wrote: Is there anyway of getting around this?
The easiest way that comes to mind is to replace the file with a desktop database. You can read/write into the database from multiple points, and export the parts to CSV if you need them.
I are Troll
|
|
|
|
|
The program that writes the file needs to allow other processes to read it; this is done when the stream is opened.
But, really, this is unlikely to be a good design. Do you really want the file? Or are you only trying to have inter-process communication? If you don't actually need the file; then find a better way.
|
|
|
|
|
You are right. This is probably not a good design but I just want to get this working as quickly as possible and it is just a short term solution.
So please can you be a little bit more specific about how exactly I let the program that writes into the file allow other programs to read the file at the same time?
A quick example of would be
string path = @"C:\Documents and Settings\";
string filename = "tester.csv";
TextWriter writer = new StreamWriter(path + filename, false);
for (int j = 0; j < 10; j++)
writer.WriteLine("{0}, {1}", j,2 * j);
Many thanks indeed.
|
|
|
|
|
You can create a FileStream that allows read access using this[^] constructor:
Stream stream = new FileStream(path + filename, FileAccess.OpenOrCreate, FileAccess.Write, FileShare.Read);
TextWriter writer = new StreamWriter(stream); Also it is a better pratice to dispose of the stream, enclosing them with the using keyword.
|
|
|
|
|
Consider using a message queue. It is robust and flexible, performs well, supports asynchronous processing (if desired) and doesn't take a lot of code so should be as quick to get up and running as messing with the files.
|
|
|
|
|
a service with a queue seems like an awesome idea for production code; you could add logging and keep adding all sorts of features as the requirements of the other applications change.
I personally have used a MemoryMapped file to exchange data between two applications because I hate using the HDD for temporary data.
EDIT: for an example of a memorymapped file: http://msdn.microsoft.com/en-us/library/dd997372%28VS.100%29.aspx[^]
modified on Monday, November 23, 2009 6:45 PM
|
|
|
|
|
I suppose a memory-mapped file is faster if there is a very large number of interactions. And I don't think message queues are installed by default on non-server editions of Windows, at least not XP. If performance is paramount there's probably nothing that can beat shared memory!
On the other hand message queues are extremely flexible. It's straightforward to share one between any number of applications (either as producers or consumers), it supports distributed transactions, the apps and the queue itself can be on the same or different computers, running the same or different Windows versions, there is built-in support for preserving a message log, they can be easily used synchronously or asynchronously, and .NET has all the wrappers needed to make it easy to work with them.
Wikipedia (usually good for getting an overview)
http://en.wikipedia.org/wiki/Microsoft_Message_Queuing
MSDN (usually good for reference, rather variable IMO on describing "the big picture")
http://msdn.microsoft.com/en-us/library/ms978425.aspx
[EDIT: changed the MSDN link to one about .NET and MSMQ; originally linked to Win32 doc.]
|
|
|
|
|
Hi,
You will have to drop down to the FileStream level to open the files in the correct manner. The writer should open the file with FileAccess.Write and FileShare.ReadWrite. The reader will obviously use FileAccess.Read but perhaps not so obviously must also specify FileShare.ReadWrite, otherwise the open will fail with exception that you have already seen.
The writer must flush the stream after each write operation to ensure that the latest data is available to the reader.
The writing code will be something along these lines:
FileStream fsw = new FileStream("filename", FileMode.Open, FileAccess.Write, FileShare.ReadWrite, 8, FileOptions.WriteThrough);
....
....
Byte[] buff = Encoding.Default.GetBytes("Data to write");
fsw.Write(buff, 0, buff.Length);
fsw.Flush();
The reader should open the file thus:
fsr = new FileStream("filename", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
That's the basics of it, assuming that there is only one writer. If that's not the case then you will need to look into locking the file.
Alan.
|
|
|
|
|
Thanks so much for so many excellent replies. I appreicate all of them
I finally 'have to' give up this 'bad' design because I can get it working but it's very messy and probably not worthwhile spending too much time on it.
Just a quick note; I get writer part working like this, which is enssentially the same as suggested.
string path = @"C:\Documents and Settings\";
string filename = "testernew1.txt";
var fi = File.Open(path + filename, FileMode.OpenOrCreate, FileAccess.Write, FileShare.ReadWrite);
var sw = new StreamWriter(fi);
for (int j = 10; j < 0; j--)
sw.Write(j);
sw.Flush();
fi.Flush();
sw.Close();
fi.Close();
Apparently, the reader part is very simliar.
I am not familiar with message queque so I am going to look into it; also someone told me that it also be done by using remote charting which I assume is more complicated than message quque?
Anyway, it would be great if someone can show some examples of either using message queue or remote charting.
Thanks again for all the replies!
|
|
|
|
|
I concur with Alan. That is the way that has worked for me many times already.
Luc Pattyn [Forum Guidelines] [My Articles]
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|