|
hi all,
am developing an excel com addin using c#. In my addin, I am supposed to
generate few buttons on the excel sheet's cells and perform their respective events on clicking.
Every thing is working fine. Every button is named 'search' and is associated
with its appropriate event handler(searchButton_Click). The button and its
event handler constitute an object(of 'result' class). Now I tried to
serialize the class Result so that I can save all the currently exisitng
'Result' objects, on the active sheet, to a file such that if I save this excel sheet and re open
the sheet, I should be able to get back the controls(de serialize) of all the
buttons present on the saved sheet. How ever in the serialization step, I am
getting an exception that says:
[System.Runtime.Serialization.SerializationException] = {"Type 'System.__ComObject' in Assembly 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked as serializable."}
Could anyone here please help me identify the exact problem here and am I
missing anything? I did mark the class 'result' as 'Serializable'. In my
'result' class I have the code to generate a button on the sheet's active
cell and that button's event handler.
The buttons am generating on the excel sheet's cells are 'MSForms.CommandButton' types.
Many thanks in advance!
|
|
|
|
|
Did ya Google it? I just did and found a crap ton of results!
The best way to accelerate a Macintosh is at 9.8m/sec² - Marcus Dolengo
|
|
|
|
|
Hey, i did google but still not able to understand why am I not able to do it.
Also, I have a doubt, if am doing some thing like this(code below) in a normal project(not an excel addin),this is working fine:
emp[] e = {
new emp(1,"Mark",5000),
new emp(2,"Mich",6000),
new emp ( 3, "Amol", 4460 ),
new emp ( 4, "Anil", 9456 ),
new emp ( 5, "Srikanth", 9500 ),
};
//SERIALIZING PART
Stream s = File.Open("c:\\New Folder\\emp.txt", FileMode.Create,FileAccess.ReadWrite);
BinaryFormatter b = new BinaryFormatter();
b.Serialize(s, e);
s.Close();
//DESERIALIZING PART
s = File.Open("c:\\New Folder\\emp.txt", FileMode.Open, FileAccess.ReadWrite);
emp[] ee = (emp[])b.Deserialize(s);
foreach (emp ez in ee)
MessageBox.Show(ez.ToString());
s.Close();
But, the same is not working when am introducing this piece of code in my excel-addin project. What could be the reason for this behavour?!
Thanks.
|
|
|
|
|
Hello
I am doing C#.NET application.I want to run a background process until my application exit.How can I implement the above using thread.
|
|
|
|
|
Like this:
using System;
using System.Threading;
namespace BackgroundThread
{
class Program
{
static void Main(string[] args)
{
Thread t = new Thread(BackgroundMethod);
t.IsBackground = true;
t.Start();
Console.ReadLine();
}
private static void BackgroundMethod()
{
while (true)
{
Thread.Sleep(1000);
Console.WriteLine("Tick");
}
}
}
}
Regards,
Rob Philpott.
|
|
|
|
|
Try using BackgroundWorker component which u can find in ToolBox of Visual Studio.
Krishnraj
|
|
|
|
|
BackGroundWorkers are for forms though, maybe his program doesn't have a form.
Though, if you use a form, the BackGroundWorker is the easiest way to go.
Just remember to lock any objects while they're being worked on, but beware of dealocks (more than one thread locking the same object).
|
|
|
|
|
Dear All
I want a simple threading example in VS 2005 C#. When i run the project it should display a label with yellow background and increases it width 1px witn 1000ms interval.
I have googled it out but they are using delegates & some are using timer but i dont want to use both.
Any kind of help will be appreciated.
Thanks.
|
|
|
|
|
I don't think that you can do this without the help of delegates. You wont be able to modify a control created in one thread from another.
Check the following links:
Invoke Required[^]
http://msdn.microsoft.com/en-us/library/ms171728(VS.80).aspx[^]
WinSolution wrote: I want a simple threading example in VS 2005 C#
You have to that do it yourself. If you are finding any issues post it here and we can help with it.
|
|
|
|
|
Yes i have tried and i found Cross Thread Error thats why i tried here if there is any way.
Basically i have shifted from Java to CSharp as i am working with C# last 8 months but i haven't learnt some new concept of c#. I was good in Java's Threading as wished if there is another way.
Thanks.
|
|
|
|
|
this can be done without using a delegate if you are doing the label updating through the thread where the label is created(means in the main form thread). if you use another thread to increase the value and the label is in the main thread you have to use the delegate. because cross thread operations are not allowed .
|
|
|
|
|
Following is the code which i tried but got error of Cross Thread.
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
ThreadStart ts = new ThreadStart(ProgressBar);
Thread th = new Thread(ts);
th.Start();
}
public void ProgressBar()
{
label1.Width += 1;
Thread.Sleep(1000);
}
}
Please share if you can figure out the problem
|
|
|
|
|
Reiterating what everyone has already mentioned. You cannot change UI state from a *non-UI* thread. ProgressBar is running on a non-UI thread. Use, BeginInvoke. Read the links already shared to you or see here[^]
|
|
|
|
|
Use Control.Invoke method to update controls on main thread.........
|
|
|
|
|
Hi,
if all you want the thread to do is move a Label, then you don't need a thread at all. Just use a Windows.Forms.Timer, that is a timer that ticks on the GUI thread, hence you can have the Tick handler manipulate Controls without any InvokeRequired/Invoke (as long as it is fast, otherwise your GUI would freeze).
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
modified on Sunday, June 12, 2011 8:37 AM
|
|
|
|
|
Hi Guys need help!
Currently i created a class file and generate to a dll file for my ASP.net web page use.
However when i recompile after editing my class file. I copy my new dll over to my web project
i can't seem to run my asp.net web page.
Do i need to recompile my ASp.net page as well after i copy my new dll file over.
KaKaShi HaTaKe
|
|
|
|
|
Did you tried Ctrl+F5. I think its due to cache. with Ctrl+F5 it will reload the dll from the host.
Please recheck if your compilation was 100% successful and confirm if you have 0 errors
|
|
|
|
|
Hmph ok....
What happen if is another C#.EXE programme that using the dll file.
The DLL edit and compile is 100% success
But in Another programme i copy the new dll over can't seem to work as well
KaKaShi HaTaKe
|
|
|
|
|
Hi,
I am working on ISO 8583-1987 standard. The problem is that my client is sending an XML file and I have to parse it in ISO 8583-1987 standard. Can anyone help me in this regard coz I have only theoritical knowledge of ISO 8583 and don't know how to practically implement it. Basically I have problrem while using bitmaps. I am not able to understand how to implemnt them and how they work.
Thanks in advance.
modified on Wednesday, February 25, 2009 1:06 AM
|
|
|
|
|
If you know the standard, what is the issue in parsing the XML file? You use classes in System.XML[^] to work with XML data.
|
|
|
|
|
Well, may be a bit very late, but i just came accross a project on sourceforge: niso8583
It contains sources fro building iso 8583 messages from xml
Have no idea whether it will help you,
Greetings
astrovirgin wrote: I am working on ISO 8583-1987 standard. The problem is that my client is sending an XML file and I have to parse it in ISO 8583-1987 standard
Where is the glue that glues together all the code snippets on The CodeProject to the ultimate solution, so I never have to work anymore?
|
|
|
|
|
Hi,
I have used the following code for Tcp client server communication ..
It works well...
I want to do the same for the Udp also...so i replaced Udp instead of Tcp...
It gives me the error:
The type or namespace name UdpListener could not be found(are you missing a using directive or a assembly reference)
Code for tcp server
using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Diagnostics;
using System.Runtime;
using System.Text;
public class Server
{
public Server()
{
}
public static void Main()
{
try
{
IPAddress ipAd = IPAddress.Parse("192.168.1.32");
TcpListener myList = new TcpListener(ipAd, 8006);
myList.Start();
Console.WriteLine("The server is running at port 8006...");
Console.WriteLine("The local End point is :" + myList.LocalEndpoint);
Console.WriteLine("Waiting for a connection.....");
Socket s = myList.AcceptSocket();
Console.WriteLine("Connection accepted from " + s.RemoteEndPoint);
byte[] b = new byte[100];
int k = s.Receive(b);
Console.WriteLine("Recieved...");
for (int i = 0; i < k; i++)
Console.Write(Convert.ToChar(b[i]));
ASCIIEncoding asen = new ASCIIEncoding();
s.Send(asen.GetBytes("The string was recieved by the server."));
Console.WriteLine("\nSent Acknowledgement");
s.Close();
myList.Stop();
}
catch (Exception e)
{
Console.WriteLine("Error..... " + e.StackTrace);
}
}
}
I replaced UdpListener instead of TcpListener...
Is that right?
Code for Tcp client
using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Diagnostics;
using System.Text;
public class Client
{
public Client()
{
}
public static void Main()
{
try
{
TcpClient tcpclnt = new TcpClient();
Console.WriteLine("Connecting.....");
tcpclnt.Connect("192.168.1.32", 8006);
Console.WriteLine("Connected");
Console.Write("Enter the string to be transmitted : ");
String str = Console.ReadLine();
Stream stm = tcpclnt.GetStream();
ASCIIEncoding asen = new ASCIIEncoding();
byte[] ba = asen.GetBytes(str);
Console.WriteLine("Transmitting.....");
stm.Write(ba, 0, ba.Length);
byte[] bb = new byte[100];
int k = stm.Read(bb, 0, 100);
for (int i = 0; i < k; i++)
Console.Write(Convert.ToChar(bb[i]));
tcpclnt.Close();
}
catch (Exception e)
{
Console.WriteLine("Error..... " + e.StackTrace);
}
}
}
What changes should i do to make it work for Udp ?
Please help with this....
|
|
|
|
|
Like TcpListener , there is no class called UdpListener in framework. You have to use Socket class with ProtocolType.Udp set. See here[^] if it helps.
|
|
|
|
|
Hi,
I am trying to convert XML to HTML using XSLT2 transformation. As I need some regular expression I used XSLT version 2. But my C# application through following exception:
“Cannot find the script or external object that implements prefix 'http://www.w3.org/2005/xpath-functions'..”
Please advice...
Thanks,
HH
|
|
|
|
|
Best way is to search with the error message. See here[^]
|
|
|
|