I have custom approval state machibe workflow , this workflow attached to list and enabled to start when any item added or changed according to requirements, when my workflow reached publish state i write custom code to change it's Moderation status to Approved then workflow finished (item state will changed as i want ) but the problem that my workflow start as new instance again :( .
You have two options:
1) Keep the workflow as starting on added or changed and add activities to the start of the workflow which check the Moderation status and exit immediately if it is already approved.
2) Have the workflow start from code in an event receiver you write and check the item before starting it.
If I understand your question you have a workflow that starts on add or change. But there are some circumstances where the item changes where you do not want the workflow to start. You cannot start the workflow in code because you need end users to add your workflow to lists themselves.
The only option then is to have the first activity in the workflow do checks to see if the workflow instance should be running. If not, exit the workflow instance. If you're building the workflow in SharePoint Designer and don't have such an activity you can build a custom activity for this in Visual Studio 2008 and then use that with SharePoint Designer. If you are building the whole workflow in Visual Studio 2008 then you can create a custom activity in Visual Studio to use with it.
i have Created small work around to fix this problem , i has created pre final state state which it redirect to final state directly , and i create Custom code activity in this state and make its code
Thread.Sleep(300);
and my problem fixed :)
Thanks God
Thanks Paul Andrew