|
hello
how do i create a nested transaction WITHOUT TransactionScope?
for example
<br />
oTxOuter = oConn.BeginTransaction();<br />
... do some work...<br />
oTxInner = oConn.BeginTransaction();<br />
... do some work...<br />
oTxInner.Commit();<br />
<br />
oTxOuter.Commit; -- Fail here can't commit twice! ADO.NET don't support this even though with TSQL you can.<br />
dev
modified on Thursday, April 16, 2009 12:37 AM
|
|
|
|
|
I'm developing a Wireless Data Transfer(WDT) applications(server and client). The server will work in pda thats why using CF and the client app will work in pc using DNF. I've already developed this type of server for PC to PC WDT and used this code to receive the data. Written in Tick event of Timer .
if (clientSocket != null && clientSocket.Connected)
{
try
{
timer1.Enabled = false;
List<byte> data = new List<byte>();
int dataLength = 0;
if (clientSocket.Available > 0)
{
byte[] buffer = new byte[4];
if (clientSocket.Available < buffer.Length)
{
LogText("Error : Inappropriate data received.");
return;
}
int read = clientSocket.Receive(buffer, SocketFlags.None);
if (read != buffer.Length)
{
LogText("Error : Unable to start reading.");
return;
}
BinaryReader br = new BinaryReader(new MemoryStream(buffer));
dataLength = br.ReadInt32();
br.Close();
data.AddRange(buffer);
}
while (data.Count != dataLength)
{
while (clientSocket.Available > 0)
{
byte[] buffer = new byte[clientSocket.Available];
int read = clientSocket.Receive(buffer, SocketFlags.None);
for (int a = 0; a < read; a++)
data.Add(buffer[a]);
Send(InstructionType.SendFileProgress, (data.Count * 100) / dataLength);
}
}
if (data.Count != 0)
ProcessReceivedData(data.ToArray());
}
catch (Exception ex)
{ LogText("Error while receiving data...\r\n" + ex.Message); }
finally { timer1.Enabled = true; }
}</byte></byte>
All works good in PC to PC as well as PC to PDA, but as you can see I'm filling all the bytes directly to the memory(List<byte> ) and I'm sure that gonna hurt the pda performance if the file size is big. e.g let assume pda process memory is 21 mb and if I'm sending a file more than 21 than pda wont response or raise out of memory exception(No idea what will happen). What I want is to directly write it to the specified place(ie. Memory card) and no effect to pda working memory. I thought to use TCPListener and TCPClient but I'm not sure that they will take over the Socket place as I used it everywhere in Client and Server. Since I never use TCP so may be TCP is better than Socket.
My question is that is there any way in Socket to that what I want or I should use TCP or any better idea ?
Thanks
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKQUFK[M`UKs*$GwU#QDXBER@CBN%
R0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia>
-----------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
Is there a way to stream folder with all subfolders and files in it?
Reason why I am looking for this is to stream folder and save it with my app and later take saved file and restore all subfolders and files with relative path to streamed folder.
|
|
|
|
|
You could just zip it together of course SharpZipLib[^]
Also saves some space as a nice bonus.
|
|
|
|
|
Thanks for reply,
and yes I am aware of that (sharpziplib, gzip, deflate...) but I need a better performance and just streamed folder.
|
|
|
|
|
On minimal compression maybe? Or how about .tar? No compression so there's no way anything else will be faster
|
|
|
|
|
Every compression will write some extra data to a stream and will use some extra cpu time to process. I am intrested in something that wil hold only data from files and theirs relative path to streamed folder.
|
|
|
|
|
Ok great so you didn't read my post
Please try again..
|
|
|
|
|
Yes I did read your post. And again thanks for quick reply. Please read this:
wikipedia.org/wiki/Tar_(file_format)
File header
The file header block contains metadata about a file. To ensure portability across different architectures with different byte orderings...
Only thing I need is data from files.
modified on Wednesday, April 15, 2009 9:19 PM
|
|
|
|
|
And performance is so important that those couple of hundred bytes is important. Ok. I see no other solution than doing it all manually. Almost everything that exists already will put some bytes into preserving the directory structure.
|
|
|
|
|
Thanks for your help. I solved the problem and as you already mentioned I write my own
It was all night job, but it was worth it.
|
|
|
|
|
There is no folder/directory stream in DNF. But you can write the entire folder in a binary file using BinaryWriter and Extract all the files from that binary file when require. All you need to think a file format. eg.
int - Number of Files
----For each file----
string - FilePath
int - FileLength
byte[FileLength] - Data
----------------------
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKQUFK[M`UKs*$GwU#QDXBER@CBN%
R0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia>
-----------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
Hi All,
I'm trying to find some info on watching for new drives being plugged into the system. The normal kind of drives like Firewire, USB drives, flash sticks, eSata etc.
The FileSystemWatcher seems to only support watching an existing drive. Would WMI be the place to go for this?
Cheers,
|
|
|
|
|
search CodeProject for WM_DEVICECHANGE
|
|
|
|
|
|
Hi,
I have a problem here, In a constructor class I am creating a synchronous socket which I use during this class is alive.
In the destructor of the class I want to Shutdown and Close the socket, but I get a very nice Exception: "ObjectDisposeException was handled" ...
How can I Shutdown and Close the socket when the object is destroyed?
Am I not suppose to shutdown or close the socket by myself?
Example:
~DDLBaseMsg()
{
if (Sender != null)
{
Sender.Shutdown(SocketShutdown.Both);
Sender.Close();
}
}
|
|
|
|
|
You should implement the IDisposable interface and call Dispose from the Finalizer. The code you currently have in the Finalizer should be moved to the Dispose method.
The Dispose method should detect if it is already disposed and not do so again. I suspect that the exception you got was because the Sender was already disposed, but you still had a reference to it.
|
|
|
|
|
Hi,
Ok, Thanks for the explanation of the IDisposable, however, I get the same error
The code is simple, I have a form which instantiate the socket owner class CBaseMsg in the constructor:
public partial class FrmMain : Form
{
CBaseMsg BaseMsg;
public FrmMain()
{
InitializeComponent();
BaseMsg = new CBaseMsg();
}
private void buttonTest_Click(object sender, EventArgs e)
{
BaseMsg.SendSomething("Test");
}
}
The class that instantiates the socket:
What I basically do is to call Dispose() from the Finalizer. I tried also to use the dispose alone, but if I put there a break point it seems that never runs.
As you can see I am not closing nor diposing the Sender instance before calling the dispose method or finalizer. The instances should be "alive" while the form exist.
Should I call dispose of the CBaseMsg from the Dispose of the FrmMain?
Another Question:
Should I really need to Shutdown() the socket? (Close() works just fine in the Finalizer and Dispose()...)
Maybe it is already automatic and I am just investing unnecessary time ...
class CBaseMsg : IDisposable
{
IPHostEntry ipHostInfo;
IPAddress ipAddress;
IPEndPoint remoteEP;
Socket Sender;
public CBaseMsg()
{
ipHostInfo = Dns.GetHostEntry("127.0.0.1");
ipAddress = ipHostInfo.AddressList[0];
remoteEP = new IPEndPoint(ipAddress, 55065);
Sender = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
Sender.ReceiveTimeout = 5000;
Sender.Connect(remoteEP);
}
~CBaseMsg()
{
Dispose();
}
public void Dispose()
{
if (Sender != null)
{
Sender.Shutdown(SocketShutdown.Both);
Sender.Close();
}
}
public void SendSomething(string Msg)
{
try
{
byte[] buffMsg = new byte[Msg.Length];
buffMsg = Encoding.ASCII.GetBytes(Msg);
int bytesSent = Sender.Send(buffMsg);
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
|
|
|
|
|
Going by some of your naming conventions I'm guessing you are coming from a C++/MFC background. That being the case you need to think about things a little differently. Well, I suspect you are, but the pendulum has swung too far the other way. You'll get what I mean in a moment.
If you have something that is disposable then you need to dispose of it rather than let the garbage handler deal with it. Just like you do in C++. This is because if it is disposable it will be holding on to resources (like a socket, file handle, GDI resource, etc.) that needs to be cleaned up as soon as you are finished with it rather than when the garbage collector gets around to it.
Finalizers are not run in any specific sequence and you cannot guarantee that the objects you reference haven't already been finalized. Basically, the CLR is clever enough to realise that if you are unreferenced, then everything you reference that isn't referenced else where is also unreferenced. It essentially chucks it into a big queue and processes it but doesn't care about order
Finalizers are really just a backstop in .NET to ensure that if the developer has forgotten to dispose of something the garbage collector can at least get a chance at dealing with it.
Since you only check for nullability on Sender may already have been closed. According to Socket.Shutdown documentation[^] the exception you are getting is raised if you attempt to shutdown a socket that is already closed.
Rather than call Shutdown and Close, you may just want to call Dispose on the socket object which will clean up the Socket for you and can be called multiple times quite safely. If the interface is implemented implicitly then you can just call Sender.Dispose() . If it is an explicity interface you'll have to use ((IDisposable)Sender).Dispose();
I hope this helps.
|
|
|
|
|
Thanks for the explanation, you are rigth I used to be a C++/MFC programmer.
I know a little about the so called garbage collector ...
Anyway, I am a bit scare about freeding resources, as you know in C++ all must be done by hand ... so I wanted to "freed" the socket,
So, one last question:
Would be better if I just do nothing at all? (I mean not call close nor shutdown anything)
I mean, maybe if I just close my form the C# would take care of disposing ... closing ... shutingdown ... etc, everything ...
or should I just call on Dispose() the Sender.Dispose() method ...
|
|
|
|
|
The general rule is that if a class implements the IDisposable interface then you are responsible for calling Dispose before allowing your object drift off into the abyss. If you reference classes as a field (member variable) your class that implement IDisposable then your class should also implement IDisposable to dispose of the objects you are referencing.
You can of course leave it all up to the CLR but then the garbage collector is non-deterministic so if you need the resource again you might not get it because it is still tied up waiting to be garbage collected. Even if you force a garbage collection it might not free up immediately.
|
|
|
|
|
ok, Thanks for the reply.
|
|
|
|
|
Good day good people,
Anyone know how I can, from within my application, access the windows Task Scheduler (on XP or Vista) and set my application to run at a specific point in the future.
I have an application that needs to process some data. When it has reached a certain point, it has to stop then launch itself again later (e.g. 12 or 48 hours later, etc...).
Thus far I've only found Task Scheduler code for office interop with C#. Any help or direction you can provide would be greatly appreciated.
Thanks in advance,
Blitz
|
|
|
|
|
|
Thank you. I will look into the information you provided.
Blitz
|
|
|
|