|
Hi!!
Can anyone tell me if i can use threading in my windows service...
i've 3 module which i want to run concurrently..
will it be easier to run by threads or on timer basis...
|
|
|
|
|
Of course you can use multiple threads inside a Windows Service.
Whether or not you should is something that we can't tell you unless you provide more information.
|
|
|
|
|
You can use threads easily in windows services. But if you can use .net 40 I'd suggest you check the new Task Parallel Library before you decide.
|
|
|
|
|
geo_m wrote: But if you can use .net 40 I'd suggest you check the new Task Parallel Library before you decide.
.net 40? I want your time machine.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
heh, too many dots - .net 4.0 is exact. We're used here to write it in this short manner .net20, .net30, .net35, .net40. I use it so often - googling, referencing, also can be found in some original microsoft comments so I didn't even realize that it's a way too ahead in time
|
|
|
|
|
You're actually expected to use threads in a service.
IMHO, using a timer to hold up your service is just an excuse to not learn threading. Too many schmucks try to use a timer to do something that it's not designed to do and doesn't fit the problem they're trying to solve.
|
|
|
|
|
I am developing a small image editing program and the output is in a compress tiff file.my program runs well in my workstation which is win7 but when i try to run my program in winXP,it throws an exception "paramater is not valid".the exception is caused by my compression that am using,which is CCITT4.is there any other way to make CCITT4 work in winXP? thanks a million guys...
|
|
|
|
|
The symptoms suggest that you're using a call to a library that is more recent than those included in WinXP. Did you write the compression routine yourself, or use a third party tool? IIRC, WinXP shipped with the .Net Framework 2.0, and since you're developing on a Win7 machine you have at least the 3.5 version installed. You might try installing the .Net Framework 3.5 package on your WinXP machine before rewriting everything.
"A Journey of a Thousand Rest Stops Begins with a Single Movement"
|
|
|
|
|
i've already installed vs2008 in winXP.I believe that .Net framework 3.5 is already included in vs2008. and the CCITT4 compression is included in vs2008. so I don't have to use a third party software or dll.is there anyway i can make the compression in winXP...thanks...
|
|
|
|
|
You're correct - VS2008 does install the 3.5 Framework. I can't think of any other reason that the routine would fail in XP but work in Win7, especially if the same tool is installed on both. I haven't worked with CCITT4, so I have no personal experience to offer. Hopefully someone more helpful will come along soon; good luck!
"A Journey of a Thousand Rest Stops Begins with a Single Movement"
|
|
|
|
|
thank you very much man...
|
|
|
|
|
Check out CCodecList[^]
Most likely the codec is not installed. The above code shows how to list the codecs installed on a machine.
|
|
|
|
|
Hi everyone!
when i run the programs of server and client, they both run and also show the acknowledgement like
>>Server Started!
>>Client No:1 started!
>>From client-1Message from Client
>>Server to client<1>1
and so on for client 2, 3 ...
but i want communication like if i type some text and then it display that text!!!
I am using visual 2010...
multithread Server program is
using System;
using System.Threading;
using System.Net.Sockets;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
TcpListener serverSocket = new TcpListener(8888);
TcpClient clientSocket = default(TcpClient);
int counter = 0;
serverSocket.Start();
Console.WriteLine(" >> " + "Server Started");
counter = 0;
while (true)
{
counter += 1;
clientSocket = serverSocket.AcceptTcpClient();
Console.WriteLine(" >> " + "Client No:" + Convert.ToString(counter) + " started!");
handleClinet client = new handleClinet();
client.startClient(clientSocket, Convert.ToString(counter));
}
clientSocket.Close();
serverSocket.Stop();
Console.WriteLine(" >> " + "exit");
Console.ReadLine();
}
}
public class handleClinet
{
TcpClient clientSocket;
string clNo;
public void startClient(TcpClient inClientSocket, string clineNo)
{
this.clientSocket = inClientSocket;
this.clNo = clineNo;
Thread ctThread = new Thread(doChat);
ctThread.Start();
}
private void doChat()
{
int requestCount = 0;
byte[] bytesFrom = new byte[10025];
string dataFromClient = null;
Byte[] sendBytes = null;
string serverResponse = null;
string rCount = null;
requestCount = 0;
while ((true))
{
try
{
requestCount = requestCount + 1;
NetworkStream networkStream = clientSocket.GetStream();
networkStream.Read(bytesFrom, 0, (int)clientSocket.ReceiveBufferSize);
dataFromClient = System.Text.Encoding.ASCII.GetString(bytesFrom);
dataFromClient = dataFromClient.Substring(0, dataFromClient.IndexOf("$"));
Console.WriteLine(" >> " + "From client-" + clNo + dataFromClient);
rCount = Convert.ToString(requestCount);
serverResponse = "Server to clinet(" + clNo + ") " + rCount;
sendBytes = Encoding.ASCII.GetBytes(serverResponse);
networkStream.Write(sendBytes, 0, sendBytes.Length);
networkStream.Flush();
Console.WriteLine(" >> " + serverResponse);
}
catch (Exception ex)
{
Console.WriteLine(" >> " + ex.ToString());
}
}
}
}
}
the Client program is
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
namespace client
{
public partial class Form1 : Form
{
System.Net.Sockets.TcpClient clientSocket = new System.Net.Sockets.TcpClient();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
msg("Client Started");
clientSocket.Connect("127.0.0.1", 8888);
label1.Text = "Client Socket Program - Server Connected ...";
NetworkStream serverStream = clientSocket.GetStream();
byte[] outStream = System.Text.Encoding.ASCII.GetBytes("Message from Client$");
serverStream.Write(outStream, 0, outStream.Length);
serverStream.Flush();
byte[] inStream = new byte[10025];
serverStream.Read(inStream, 0, (int)clientSocket.ReceiveBufferSize);
string returndata = System.Text.Encoding.ASCII.GetString(inStream);
msg("Data from Server : " + returndata);
}
public void msg(string mesg)
{
textBox1.Text = textBox1.Text + Environment.NewLine + " >> " + mesg;
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
}
}
Plzzzzz guide me.........
Regards
|
|
|
|
|
yum 2010 wrote: but i want communication like if i type some text and then it display that text!!!
You mean when you press "A", that the other side immediately receives that character and displays it?
yum 2010 wrote: Plzzzzz guide me
Guiding someone trough a forest is a level beyond pointing the right direction
I are Troll
|
|
|
|
|
Eddy Vluggen wrote: You mean when you press "A", that the other side immediately receives that character and displays it?
yeah!!
|
|
|
|
|
Then send a message whenever a key is pressed
You're already sending messages, I guess you can adapt it to send a message on every keystroke.
I are Troll
|
|
|
|
|
Eddy Vluggen wrote: I guess you can adapt it to send a message on every keystroke.
hey can yu guide me that how can i do this??
|
|
|
|
|
yum 2010 wrote: hey can yu guide me that how can i do this??
I can't.
The code that you posted is a basic client/server example. I suggest you search for multiple chat-applications and study them.
I are Troll
|
|
|
|
|
Eddy Vluggen wrote: I can't.
The code that you posted is a basic client/server example. I suggest you search for multiple chat-applications and study them.
okay!
|
|
|
|
|
sorry for my english
I'm creating a webusercontrol and i need to obtain the classes types from my solution, How Can I do it
|
|
|
|
|
Do you mean object GetType() - then see here.
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
|
|
|
|
|
Greetings,
I have a file which is binary. It contains lots of text encoded in UTF8 and binary blobs. I am trying to find a specific section which is 'xref' located somewhere at the end of the file.
So I need to open the file, read the file from the beginning, and find something.
What I have, below, is probably horribly inefficient and perhaps even plain wrong.
Hence I write this in the hope of getting advice from my more experienced peers...
First off, I am maintaining a lock on the file with the filereader, right? Isn't that bad?
Please tell how you would do this
thanks,
<pre>
string path,data;
Boolean munching = true;
long length;
int offset = 0;
int count = 4;
UTF8Encoding utf8 = new UTF8Encoding();
if (txtFilePath.Text != "")
{
path = txtFilePath.Text;
if (File.Exists(path))
{
FileStream fs = File.OpenRead(path);
length = fs.Length;
byte[] buffer = new byte[count];
offset = Convert.ToInt32(length) - count;
int lastBytes = Convert.ToInt32(length-count);
fs.Seek(offset, 0);
while (munching)
{
fs.Read(buffer, 0, count);
data = utf8.GetString(buffer);
if (data == "xref")
{
// Yay! I've finally figured this part out.
}
offset = offset - 1;
fs.Seek(offset, 0);
</pre>
-- Modified Wednesday, July 7, 2010 12:27 PM
|
|
|
|
|
The text "xref" contains only letters in the 7bit ASCII range, so you don't even need to handle funny UTF8 things (multi-byte characters never contain anything from the ASCII range), you can pretend it is a binary file and search for the byte sequence 0x78, 0x72, 0x65, 0x66
|
|
|
|
|
There is one very large inefficiency in there: Every time around the loop you convert the whole buffer to utf8, and then extract a substring from it.
So, the first time, you read 100 bytes, convert 100 bytes, and then extract 100 bytes into a string.
The second time, you read 100 bytes, convert 200 bytes, and then extract 100 bytes into a string.
The third time, you read 100 bytes, convert 300 bytes, and then extract 100 bytes into a string.
...
Then you do a comparison to check if the whole 100 bytes you read in are "xref" - a four byte string. I think I can guarantee it will only work if the last four bytes in your file are 'x', 'r', 'e' and 'f' in that order...
Did you know:
That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.
|
|
|
|
|
By The Way:
1) If it's at the end of the file, why do you start reading from the beginning?
2) What if it is in two blocks ("xr" at the end of one, "ef" at the start of the next)?
Did you know:
That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.
|
|
|
|