Both of them prevent the aircraft from stalling, so is there any difference between them? The wing fence doesn't produce a vortex, so how does it work?
The wing fence is more or less what it is called- a fence. For swept wing aircraft, the local flow is not along the direction of flight, as there is a significant spanwise flow from the center towards the tips. It can be seen in the following figure.
Image from fuckyeahfluiddynamics.tumblr.com
The end result is that the boundary layer continues to grow (thicken) in this direction, with outboard regions more prone to stall than inboard ones. Basically, the wing fences stop the spanwise flow, with the result being a new (thinner) boundary layer starts on the other side of the fence.
In case of a vortex generator, the VGs basically create a vortex which re-invigorates the boundary layer by mixing free stream air with that of the boundary layer, thereby preventing separation.