|
Hi
I'm using list view to display files and folders of a directory. I suppose to provide an option for sorting that is when i hit column header it should get sort and group which means files should be club together and folders as like XP Windows explorer sorting. For me Name,Size sorting are works fine but date sorting doesn't looks good as files and folders are shuffled together but name and size are works as expected. Please advise.
Thanks
...
|
|
|
|
|
|
Hi All,
I am sending a structure object to another machine through TCP/IP by connecting through socket,so that i have to convert this object into byte array and also viceversa...
Please help me,it is urgent.
Regards,
Lalit Narayan
|
|
|
|
|
/ Convert an object to a byte array
private byte[] ObjectToByteArray(Object obj)
{
if(obj == null)
return null;
BinaryFormatter bf = new BinaryFormatter();
MemoryStream ms = new MemoryStream();
bf.Serialize(ms, obj);
return ms.ToArray();
}
private Object ByteArrayToObject(byte[] arrBytes)
{
MemoryStream memStream = new MemoryStream();
BinaryFormatter binForm = new BinaryFormatter();
memStream.Write(arrBytes, 0, arrBytes.Length);
memStream.Seek(0, SeekOrigin.Begin);
Object obj = (Object) binForm.Deserialize(memStream);
return obj;
}
[Serializable] attribute need to be enable serialization
|
|
|
|
|
Hi
Thanks for ur reply......
When i am deserializing the object from bytes array,then i am getting error
"Unable to find assembly 'DeviceApp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'."
Please give any solution for that.
Regards,
Lalit Narayan
|
|
|
|
|
Hi,
I have a listening port using socket, number of clients will connect with that port. Lot of messages like images,text,docs etc are send between the clients using the listening port. These communication will occur concurrently.
eg: a,b,c,d .... are connected to a listening port. 'A' sent a image to 'B', at that same time 'C' send an text to 'D', 'B' to 'D', 'D' to 'A'.......etc at the same point of time.
My question.
Will the listening port can manage all these correctly?
Will there be any traffic jam? or slow in communucation?
Can the listening port manage any number of clients?
What is the standard way to manage these messages?
Can i open diffrent port for diffrent type of messages?
I am using socket.Blocking = true; method.
Thankyou
YPKI
|
|
|
|
|
If you say
socket.Blocking = true
then it is more like Synchronous call, looks like you might require Asynchronous environment as you are trying to handle multiple clients.
|
|
|
|
|
|
i am writing some code, if will act different ways on x64 and x86,
does there is a way to justify the code is compiled by x64 or x86,
as i know i cpp i can use
#ifdef __x64
doA
#elif __x86
doB
#endif
|
|
|
|
|
sorry, but why the hell is your first name "Dracula"?
dev
|
|
|
|
|
just for fun.
there is a movie with this name, and some games
|
|
|
|
|
Check the Operation System Name.In X64 Bit Operation System have X64.
mailto: anubhava.prodata@gmail.com
|
|
|
|
|
for now, i am just using the return IntPtr.Size == 8,
|
|
|
|
|
Good People,
I have a log file that I open to write to while my application is running. If I don't close it and my application exits, can I write to it again when my application opens? If I don't close it and my application exits, will it cause operating system instability or any other problems?
Thanks,
Blitz
|
|
|
|
|
Hi,
a Windows process cleans up after itself upon exit, no matter what.
So your old log file will be closed; it may however not contains the latest log entries, since these probably were still in some buffers somewhere.
That is why I often implement a log method as an open-for-append, write, close sequence, increasing the probability the last entries are in the file; they probably are the ones you want to see when things suddenly go wrong! Of course open/write/close is slower than a simple write, so you may want to switch back to a simple write in a release build.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Thanks Luc, I appreciate the information.
|
|
|
|
|
How can I read the photo taken date(not the created date or modified date). I found on Google that can be do by propertyItems. There’s no date taken property in Property items.
Is there any possible way to read the photo taken date???
A S E L A
|
|
|
|
|
Some file formats (including JPEG) allow for a lot of metadata, and most camera's seem to provide at least some of these pieces of information.
Here is some code that may be useful to you; I will not provide support on it though.
string s=readImageProperty(image, 0x132);
log("datetime="+s);
DateTime exposureDate=ParseExposureDate(s, equipModel);
log("Exposure DateTime = "+DateToString(exposureDate, false, ""));
private static string readImageProperty(Image image, int ID) {
try {
PropertyItem pi=image.GetPropertyItem(ID);
if(pi!=null) {
if(pi.Type==2) {
return ASCIIencoding.GetString(pi.Value, 0, pi.Len-1);
}
if(pi.Type==5) {
byte[] bb=pi.Value;
uint uNominator=BitConverter.ToUInt32(bb, 0);
uint uDenominator=BitConverter.ToUInt32(bb, 4);
if(uDenominator==1) return uNominator.ToString();
return uNominator.ToString()+"/"+uDenominator.ToString();
}
}
} catch {
}
return null;
}
private static DateTime ParseExposureDate(string exposure, string equipModel) {
DateTime dt=DateTime.MinValue;
bool OK=false;
if(!OK) {
OK=DateTime.TryParseExact(exposure, "yyyy:MM:dd HH:mm:ss",
null, DateTimeStyles.None, out dt);
}
log("ParseExposureDate: \""+exposure+"\" >>> "+dt);
return dt;
}
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
|
browsing the documentation for 10 seconds would reveal the namespace.
I am not in the spoon feeding business, I try to provide added value.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
hello (First of all sorry about long stack trace)
I ran into this problem with System.Data.OracleClient - "System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
I checked the following, none resolved the problem:
(a) Make sure M$ DTC startup automatic
(b) C:\oraclexe\app\oracle\product\10.2.0\server\NETWORK\ADMIN\sqlnet.ora
Change from:
SQLNET.AUTHENTICATION_SERVICES = (NTS)
To:
SQLNET.AUTHENTICATION_SERVICES= (NONE)
(c) Set OracleConnection.Unicode to true, i.e. add the following to connection string
Unicode=true;
(d) Be careful with LONG, LONG RAW, OBJECT, XMLTYPE - try comment out first if any.
REF: http://www.devart.com/forums/viewtopic.php?p=42223&sid=603c2d8bf01329ec2e98df036d5ef2da
I can't find anything "funny" with my Person's table.
<br />
CREATE TABLE PERSON (<br />
Id numeric(19,0) NOT NULL,<br />
FirstName nvarchar2 (50) NOT NULL,<br />
MiddleName nvarchar2 (50) NULL,<br />
LastName nvarchar2 (50) NOT NULL,<br />
PrimaryEmail nvarchar2 (190) NULL,<br />
PersonType int default 1 NOT NULL, <br />
CreateDate date default sysdate NULL, <br />
CreatedBy numeric(19,0) default -1 NULL,<br />
LastUpdate date NULL,<br />
LastUpdateBy numeric(19,0) NULL,<br />
<br />
CONSTRAINT PK_PERSON PRIMARY KEY (Id),<br />
CONSTRAINT UK_PERSON_PRIMARYEMAIL UNIQUE (PrimaryEmail)<br />
)<br />
And my NHibernate mapping file (Googled a bit don't think it is problem with NHibernate, also this Save works fine with MySQL and M$SQL, only Oracle making trouble):
<br />
class name="Person" table="Person"<br />
id name="Id" column="Id" type="Int64" unsaved-value="0"<br />
generator class="sequence"<br />
param name="sequence" SYSTEMUSER_SEQ /param<br />
/generator<br />
/id<br />
property name="PrimaryEmail" column="PrimaryEmail" type="String(255)"/<br />
<br />
property name="Type" column="PersonType" type="Int32"/<br />
<br />
component name="Name" class="xxxxx.Util.Name"<br />
property name="FirstName" column="FirstName" type="String(50)" /<br />
property name="MiddleName" column="MiddleName" type="String(50)" /<br />
property name="LastName" column="LastName" type="String(50)" /<br />
/component<br />
component name="BasicAudit" class="xxxxx.Util.Security.BasicAudit"<br />
property name="CreateDate" column="CreateDate" type="DateTime"/<br />
property name="CreatedBy" column="CreatedBy" type="Int64"/<br />
property name="LastUpdate" column="LastUpdate" type="DateTime"/<br />
property name="LastUpdateBy" column="LastUpdateBy" type="Int64"/<br />
/component<br />
joined-subclass name="xxxxx.Util.Security.SystemUser" table="SystemUser"<br />
key column="PersonId" /<br />
property name="Logon" column="Logon" type="String(50)" /<br />
property name="PasswdHash" column="PasswdHash" type="Int32"/<br />
/joined-subclass<br />
/class<br />
And here's application code:
<br />
public virtual long Save(ref IGenericTO oPerson)<br />
{<br />
...<br />
<br />
try<br />
{<br />
<br />
using (oScope = new TransactionScope())<br />
{<br />
DBSession.Flush();<br />
nGeneratedId = (long)DBSession.Save(oPerson);<br />
DBSession.Flush();<br />
<br />
... other database operation done in ADO.NET ...<br />
<br />
oScope.Complete();<br />
}<br />
}<br />
catch (Exception ex)<br />
{<br />
....Util.ApplicationException.Throw("Save failed", null, oPerson.ToString(), ex);<br />
}<br />
<br />
return nGeneratedId;<br />
}<br />
(e) M$ Hot fix - as suggested by http://forums.asp.net/p/675515/675515.aspx
I downloaded "303312_intl_i386_zip.exe " from following M$ URL.
Unfortunately on my XP box with:
* .NET 3.5 SP1
* Oracle 10g Express
* System.Data.OracleClient Runtime version v2.0.50727
I had the following error while trying to install the fix:
"The upgrade patch canno be installed by the Windows Installer service because the program to be upgraded may be missing, or the upgrade patch may update a different version of the program. Verify that the program to be upgraded exists on your computer and that you have the correct upgrade path."
The fix does indicate that it is intended for .NET 2.0 however:
"Article ID: 923028 - Last Review: March 25, 2009 - Revision: 4.0 FIX: Error message when you run a .NET Framework 2.0 Remoting application: "Unhandled Exception: System.AccessViolationException"
Download fix:
https://connect.microsoft.com/VisualStudio/Downloads/DownloadDetails.aspx?DownloadID=6003&wa=wsignin1.0
Any suggestion? Help!
REF:
http://forums.oracle.com/forums/thread.jspa?threadID=415053&tstart=0
http://www.devart.com/forums/viewtopic.php?p=42223&sid=603c2d8bf01329ec2e98df036d5ef2da
http://forums.asp.net/p/675515/675515.aspx
Sorry for long stack trace
<br />
2009-04-09 07:31:24,609 [10] ERROR SimpleConsoleTest - xxxxx.Util.ApplicationException Exception context: xxxxx.Util.ApplicationExceptionContext, Subject: Save failed, Description: xxxxx.Util.Person, Id:-1, Name:xxxxx.Util.Name, FirstName:John, MiddleName:, LastName:Kennedy, PrimaryEmail:john.kennedy@gmail.com, Type:undefined, GenericObj:object type: xxxxx.Util.Generic.GenericObject, object name: , object classifier: Person, TypeName: xxxxx.Util.Person, DAOTypeName: xxxxx.Util.PersonDAO, Util, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null, DAOCreateInstanceArg: , CreateDate: 4/9/2009 7:31:19 AM, Properties: , Parents count:0, Children:, DatabaseInitiated: False, BasicAudit:xxxxx.Util.Security.BasicAudit, CreateDate:4/9/2009 7:31:19 AM, CreatedBy:-1, LastUpdate:1/1/1753 12:00:00 AM, LastUpdateBy:-1, StackTrace: at xxxxx.Util.ApplicationException.Throw(String strSubject, String strSummary, String strDescription, Exception oInnerException) in C:\dev\xxxxx\NET3.0\Util\ApplicationException.cs:line 176<br />
at xxxxx.Util.PersonDAO.Save(IGenericTO& oPerson) in C:\dev\xxxxx\NET3.0\Util\PersonDAO.cs:line 349<br />
at xxxxx.NUnitTest.TestDAOUtil.TestSaveAndSelectByKey(IGenericTO& o) in C:\dev\xxxxx\NET3.0\NUnitTest\TestDAOUtil.cs:line 349<br />
at xxxxx.NUnitTest.TestDAOUtil.TestDAO(Boolean bTestDelete) in C:\dev\xxxxx\NET3.0\NUnitTest\TestDAOUtil.cs:line 278<br />
at SimpleConsoleTest.Program.TestPeronDAO() in C:\dev\xxxxx\NET3.0\SimpleConsoleTest\Program.cs:line 131<br />
at SimpleConsoleTest.Program.Main() in C:\dev\xxxxx\NET3.0\SimpleConsoleTest\Program.cs:line 45<br />
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)<br />
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)<br />
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()<br />
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)<br />
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)<br />
at System.Threading.ThreadHelper.ThreadStart()<br />
{Inner Exception: NHibernate.ADOException: cannot open connection ---> System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.<br />
at System.Data.Common.UnsafeNativeMethods.OraMTSEnlCtxGet(Byte[] lpUname, Byte[] lpPsswd, Byte[] lpDbnam, OciHandle pOCISvc, OciHandle pOCIErr, UInt32 dwFlags, IntPtr& pCtxt)<br />
at System.Data.OracleClient.TracedNativeMethods.OraMTSEnlCtxGet(Byte[] userName, Byte[] password, Byte[] serverName, OciHandle pOCISvc, OciHandle pOCIErr, IntPtr& pCtxt)<br />
at System.Data.OracleClient.OciEnlistContext..ctor(Byte[] userName, Byte[] password, Byte[] serverName, OciServiceContextHandle serviceContextHandle, OciErrorHandle errorHandle)<br />
at System.Data.OracleClient.OracleInternalConnection.Enlist(String userName, String password, String serverName, Transaction transaction, Boolean manualEnlistment)<br />
at System.Data.OracleClient.OracleInternalConnection.Activate(Transaction transaction)<br />
at System.Data.ProviderBase.DbConnectionInternal.ActivateConnection(Transaction transaction)<br />
at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject)<br />
at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)<br />
at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)<br />
at System.Data.OracleClient.OracleConnection.Open()<br />
at NHibernate.Connection.DriverConnectionProvider.GetConnection()<br />
at NHibernate.Impl.SessionFactoryImpl.OpenConnection()<br />
--- End of inner exception stack trace ---<br />
at NHibernate.Impl.SessionFactoryImpl.OpenConnection()<br />
at NHibernate.AdoNet.ConnectionManager.GetConnection()<br />
at NHibernate.AdoNet.AbstractBatcher.Prepare(IDbCommand cmd)<br />
at NHibernate.AdoNet.AbstractBatcher.ExecuteReader(IDbCommand cmd)<br />
at NHibernate.Id.SequenceGenerator.Generate(ISessionImplementor session, Object obj)<br />
at NHibernate.Event.Default.AbstractSaveEventListener.SaveWithGeneratedId(Object entity, String entityName, Object anything, IEventSource source, Boolean requiresImmediateIdAccess)<br />
at NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.SaveWithGeneratedOrRequestedId(SaveOrUpdateEvent event)<br />
at NHibernate.Event.Default.DefaultSaveEventListener.SaveWithGeneratedOrRequestedId(SaveOrUpdateEvent event)<br />
at NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.EntityIsTransient(SaveOrUpdateEvent event)<br />
at NHibernate.Event.Default.DefaultSaveEventListener.PerformSaveOrUpdate(SaveOrUpdateEvent event)<br />
at NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.OnSaveOrUpdate(SaveOrUpdateEvent event)<br />
at NHibernate.Impl.SessionImpl.FireSave(SaveOrUpdateEvent event)<br />
at NHibernate.Impl.SessionImpl.Save(Object obj)<br />
<b>at xxxxx.Util.PersonDAO.Save(IGenericTO& oPerson) in C:\dev\xxxxx\NET3.0\Util\PersonDAO.cs:line 332 {Inner Exception: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.</b><br />
at System.Data.Common.UnsafeNativeMethods.OraMTSEnlCtxGet(Byte[] lpUname, Byte[] lpPsswd, Byte[] lpDbnam, OciHandle pOCISvc, OciHandle pOCIErr, UInt32 dwFlags, IntPtr& pCtxt)<br />
at System.Data.OracleClient.TracedNativeMethods.OraMTSEnlCtxGet(Byte[] userName, Byte[] password, Byte[] serverName, OciHandle pOCISvc, OciHandle pOCIErr, IntPtr& pCtxt)<br />
at System.Data.OracleClient.OciEnlistContext..ctor(Byte[] userName, Byte[] password, Byte[] serverName, OciServiceContextHandle serviceContextHandle, OciErrorHandle errorHandle)<br />
at System.Data.OracleClient.OracleInternalConnection.Enlist(String userName, String password, String serverName, Transaction transaction, Boolean manualEnlistment)<br />
at System.Data.OracleClient.OracleInternalConnection.Activate(Transaction transaction)<br />
at System.Data.ProviderBase.DbConnectionInternal.ActivateConnection(Transaction transaction)<br />
at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject)<br />
at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)<br />
at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)<br />
at System.Data.OracleClient.OracleConnection.Open()<br />
at NHibernate.Connection.DriverConnectionProvider.GetConnection()<br />
at NHibernate.Impl.SessionFactoryImpl.OpenConnection()<br />
dev
|
|
|
|
|
I have created an application that seems to be using quite a bit amount of memory. This application contacts the SQL server quite often. It also using some simple threading. The thing is, I have closed everything that was ever opened and disposed it. Any threads being used have been disposed as well. This is why I am a little confused. After inserting pictures in this inventory application, after I was done, I looked in the task manager and the app was up over 300,000kb in memory usage. Now it seems I've looked over something on closing?
Or is C# slow at garbage collection?
|
|
|
|
|
I guess my question was is that a large amount or not? I mean 300mb seems large. I didn't wait long to see if it went down.
|
|
|
|
|
Hi,
Task Manager is not providing the right information. It shows how much memory an app is currently entitled to use, not how much is actually used. When a .NET app needs memory, it either looks for free memory inside the process, or asks Windows for more. When objects die, their memory is garbage collected but not necessarily returned to Windows.
One experiment you could do is this: minimize your main form, then watch Task Manager. The number will be lower now. If that reduced number stays somewhat constant over time (each time minimizing), then as a first approximation your app isn't loosing/wasting memory. If that number keeps growing, your app probably has some memory leaks.
I often include a permanent memory observer in the app itself: have a timer regularly update a label and have it show the value of Environment.WorkingSet (divide by 1024*1024 to get megabytes). That is more comfortable and more reliable than the TM numbers.
PS: large is a relative notion. If your system has ample memory and Windows is willing to give 500MB of memory to your app, then the app will use that to its advantage, i.e. the need to garbage collect will be reduced.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
So I open and close my window, looking to see if the memory usage gets smaller each time and stays constant?
I will try the WorkingSet tomorrow when I get to work and see how it does.
I know you have helped me before and I appreciate it!
|
|
|
|
|